Borislav Hadzhiev
Wed Sep 22 2021·2 min read
Photo by Catalin Sandru
To allow public read access to an S3 bucket:
Permissions
tabBlock public access (bucket settings)
section, click on the Edit
button, uncheck the checkboxes and click on Save changes
Permissions
tab scroll down to the Bucket policy
section and click
on the Edit
button. Paste the following policy into the textarea to grant
public read access to all files in your S3 bucket.YOUR_BUCKET_NAME
placeholder with your bucket's name.{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Principal": "*", "Action": [ "s3:GetObject" ], "Resource": "arn:aws:s3:::YOUR_BUCKET_NAME/*" } ] }
For example, the bucket policy of an s3 bucket with the name my-bucket
will
look like:
Save the changes you've made to the bucket's policy and your bucket will have public read access enabled.
(Optional) - If you need to access your bucket with http request from the browser, you have update the bucket's Cross-origin resource sharing (CORS) options to allow your frontend's requests
In the Permissions
tab of your S3 bucket, scroll down to the
Cross-origin resource sharing (CORS)
section and click on the Edit
button
Paste the following JSON into the textarea and save the changes
[ { "AllowedHeaders": [ "Authorization", "Content-Length" ], "AllowedMethods": [ "GET" ], "AllowedOrigins": [ "*" ], "ExposeHeaders": [], "MaxAgeSeconds": 3000 } ]
To test that your bucket has public read access enabled:
Objects
tab in your S3 bucketCopy URL
button at the top, top copy the public URL of the
fileNote that you'll see a red badge with the text Publicly accessible
next to
your bucket's name.
In our case the bucket policy only grants public access on the bucket, other people could not add objects to your S3 bucket.