Skip to content

Code for public, read only access to a bucket

0

I'm trying to make a public, read only access to a bucket and can follow the initial steps. However, I cannot find the code to use for the bucket policy as the one in the Policy Examples is for using tags which I'm not doing. I'm new to S3 so any help is appreciated thanks

1 Answer
0
Accepted Answer

To make your S3 bucket publicly readable, you'll need to:

  1. First, modify the Block Public Access settings for your bucket:
  • Navigate to your bucket in the S3 console
  • Click on the "Permissions" tab
  • Find "Block public access" and click "Edit"
  • Uncheck "Block all public access" (you may need to uncheck all four individual settings)
  • Save the changes
  1. Then add a bucket policy that grants public read access:
  • In the "Permissions" tab, go to "Bucket policy"
  • Add the following policy (replace "YOUR-BUCKET-NAME" with your actual bucket name):
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "PublicReadGetObject",
"Effect": "Allow",
"Principal": "*",
"Action": [
"s3:GetObject"
],
"Resource": [
"arn:aws:s3:::YOUR-BUCKET-NAME/*"
]
}
]
}

This policy grants anyone on the internet permission to read any object in your bucket. The /* at the end of the Resource ARN indicates that the policy applies to all objects within the bucket.

If you get an error when saving the policy, double-check that:

  • The bucket name in the policy exactly matches your actual bucket name
  • You've properly disabled the Block Public Access settings
  • The JSON syntax is correct

Remember that making a bucket public means anyone can access its contents, so ensure you don't store sensitive information there.
Sources
Setting permissions for website access - Amazon Simple Storage Service
frontend s3 bucket access | AWS re:Post
Tutorial: Configuring a static website using a custom domain registered with Route 53 - Amazon Simple Storage Service

answered 16 days ago
EXPERT
reviewed 16 days ago
  • fantastic - thanks for the code

  • This code works perfectly!