322

How can I set a bucket in Amazon S3 so all the files are publicly read-only by default?

2
  • 19
    I'm annoyed this question was flagged as off topic. AWS is critical for serious programmers. I would add u can use cli sync command with acl argument like this: aws s3 sync ./local-folder-name s3://remote-bucket-name --acl=public-read Feb 27, 2019 at 19:29
  • This answer to a similar post may help: stackoverflow.com/a/23102551/475882
    – jaxxbo
    Apr 12, 2019 at 1:12

2 Answers 2

523

You can set a bucket policy as detailed in this blog post:

http://ariejan.net/2010/12/24/public-readable-amazon-s3-bucket-policy/


As per @robbyt's suggestion, create a bucket policy with the following JSON:

{
    "Version": "2008-10-17",
    "Statement": [
        {
            "Sid": "AllowPublicRead",
            "Effect": "Allow",
            "Principal": {
                "AWS": "*"
            },
            "Action": [
                "s3:GetObject"
            ],
            "Resource": [
                "arn:aws:s3:::bucket/*"
            ]
        }
    ]
}

Important: replace bucket in the Resource line with the name of your bucket.

10
  • When using official AWS CLI arn:aws:s3:::bucket also needs to be added to the Resource array. (So without the /*.) I hope this helps others who were struggling with this like me.
    – silvenon
    Feb 18, 2015 at 16:03
  • My bad. This is needed only if you plan to sync, not just view the bucket.
    – silvenon
    Feb 18, 2015 at 16:05
  • 7
    To support anonymous access through python's boto, in addition to setting this policy, I also had to grant List privilege to Everyone in the Properties > Permissions section of the bucket. Jul 7, 2015 at 19:33
  • what is the rule of writeing Version? I am using current date 2017-11-16, it reports:Error: The policy must contain a valid version string
    – Timothy.Li
    Nov 16, 2017 at 10:11
  • 1
    @Timothy.Li did you remember to wrap it in quotes? "2017-11-16",
    – froggomad
    Feb 16, 2018 at 14:22
61

Amazon provides a policy generator tool:

https://awspolicygen.s3.amazonaws.com/policygen.html

After that, you can enter the policy requirements for the bucket on the AWS console:

https://console.aws.amazon.com/s3/home

3

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.