Skip to content

Instantly share code, notes, and snippets.

@philfreo
Created October 6, 2012 01:27
Show Gist options
  • Select an option

  • Save philfreo/3843375 to your computer and use it in GitHub Desktop.

Select an option

Save philfreo/3843375 to your computer and use it in GitHub Desktop.
AWS S3 bucket policy to make all files public (+CORS)
<?xml version="1.0" encoding="UTF-8"?>
<CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
<CORSRule>
<AllowedOrigin>*</AllowedOrigin>
<AllowedMethod>GET</AllowedMethod>
<MaxAgeSeconds>3000</MaxAgeSeconds>
<AllowedHeader>Authorization</AllowedHeader>
</CORSRule>
<CORSRule>
<AllowedOrigin>*</AllowedOrigin>
<AllowedMethod>PUT</AllowedMethod>
<MaxAgeSeconds>3000</MaxAgeSeconds>
<AllowedHeader>Content-Type</AllowedHeader>
<AllowedHeader>x-amz-acl</AllowedHeader>
<AllowedHeader>origin</AllowedHeader>
</CORSRule>
</CORSConfiguration>
{
"Statement": [
{
"Sid": "AllowPublicRead",
"Effect": "Allow",
"Principal": {
"AWS": "*"
},
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::your-bucket-name/*"
}
]
}
@philfreo
Copy link
Copy Markdown
Author

@dangerfarms
Copy link
Copy Markdown

Can you confirm this still works? My OPTIONS request to s3 just freezes and nothing ever happens.

@dangerfarms
Copy link
Copy Markdown

Nope?

@chosak
Copy link
Copy Markdown

chosak commented Feb 3, 2015

@philfreo thanks for the helpful blog post and code examples.

@dangerfarms I just implemented this and had to make some minor changes. Specifically, Chrome was reporting a net::ERR_INSECURE_RESPONSE error on the OPTIONS call, because the certificate for https://<your bucket name>.s3.amazonaws.com isn't trusted.

To modify the code above, you could do something like

url = 'https://s3.amazonaws.com/%s/%s' % (
    app.config['AWS_EMAIL_ATTACHMENTS_BUCKET_NAME',
    object_name
)

This has the same effect -- use this URL both as the returned value for 'url' as well as in your signed request.

@tomasdev
Copy link
Copy Markdown

tomasdev commented Dec 3, 2018

@philfreo THANK YOU! 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment