I recently wrote a tutorial on how to upload an image to S3, but I encountered an issue when the uploaded image couldn’t be accessed publicly in read mode. If you’re facing the same problem, don’t worry. I’ll guide you through the steps to make your S3 buckets public.
First, let’s talk about the “Block public access” setting. Disabling this block alone doesn’t make your images accessible to the public. So, what should you do?
To begin, you can start by granting public access to individual files. By setting the permissions of the specific file to “Read” for “Everyone (public access),” you can make that file accessible to the public. However, if you want to provide public access to all the files in your bucket, you’ll need to take an additional step.
You’ll need to set a Bucket Policy. It’s not something you can achieve through the UI alone. Follow these steps from the bucket permissions page:
- Go to the bucket permissions page.
- Add the following Bucket Policy:
{
"Version": "2008-10-17",
"Statement": [
{
"Sid": "AllowPublicRead",
"Effect": "Allow",
"Principal": {
"AWS": "*"
},
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::YOURBUCKETNAME/*"
}
]
}
Note: Replace “YOURBUCKETNAME” with the actual name of your bucket.
Setting this Bucket Policy allows all AWS accounts to access your bucket’s objects. Once you’ve added the policy, you can manage the “Block public access” setting as desired.
That’s it! Now your files, including images, should be publicly accessible. Follow these steps, and you’ll have no trouble making your S3 buckets public.