Easy AWS S3 IP Whitelisting

Working on a website hosted in AWS S3, but don’t want to give public access yet? Easy fix.

First navigate to your console and go to S3 service.

Next, navigate to the bucket where your static site is hosted and go to Permissions tab, then click on bucket policy.

to

In a new browser tab, navigate to https://www.whatismyip.com/    to perform an IP address lookup.

After knowing the IP address, enter the following JSON policy into the policy editor. You will need to modify the two items in bold that correspond to your bucket name and IP address.

[cc lang=”json”]{
“Version”: “2012-10-17”,
“Id”: “S3PolicyId1”,
“Statement”: [
{
“Sid”: “IPAllow”,
“Effect”: “Allow”,
“Principal”: “*”,
“Action”: “s3:*”,
“Resource”: “arn:aws:s3:::YOUR_BUCKET/*”,
“Condition”: {
“IpAddress”: {
“aws:SourceIp”: [
“123.456.789.012”
]
}
}
}
] }[/cc]

Click save, and then your index.html document will be accessible form the machine you are on.

Recommended Posts