In this case, your bucket name does not matter
- Create the bucket (I'll use
myassets) as an example - In the S3 interface, goto the bucket's Properties
- Under Permissions add a grantee: - Grantee: Everyone - Check only "View Permissions"
- Add/Edit the bucket policy to reflect:
```json
{
"Version": "2008-10-17",
"Statement": [
{
"Sid": "PublicReadForGetBucketObjects",
"Effect": "Allow",
"Principal": {
"AWS": "*"
},
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::assets.example.com/*"
}
]
}
```
- Under "Static Website Hosting" toggle "Enable website hosting"
You'll need to specify index & error documents but they don't have to exist.
- Take note of the "Endpoint:" that looks something like:
myassets.s3-website-us-east-1.amazonaws.com
Your assets will now be accessible there. So a key called avatar.jpg would be
available at http://myassets.s3-website-us-east-1.amazonaws.com/avatar.jpg
For the sake of the example, I'll be hosting my content at assets.example.com
- Create a bucket named
assets.example.com - Follow the same steps from the non-explicit domain procedure
- Update your DNS to have a CNAME from
assets.example.comto the endpoint you found above.
- With S3, there are IAM policies and bucket policies; you'll only need to deal with the latter for this use case
- Remember that all S3 bucket names must be globally unique
- The S3 bucket name must be identical to the hostname you CNAME (if you choose to use an explicit hostname)