How do I fix an AWS S3 bucket policy and public permissions access denied error?

Photo by Kyle Glenn on Unsplash

Fix it in under 3 minutes

So you are probably using an S3 bucket to host a react website or want to serve images to the public.

However, nothing seems to make sense, and you get access denied when trying to view an object using its URL.

Don't worry; fixing this is very simple.

Let's begin.

1. Unchecking "block all public access."

This check-box appears when you first create your bucket, so if you missed it, head to the S3 dashboard, click on your bucket and go to the permissions tab.

How do I fix an AWS S3 bucket policy and public permissions access denied error?

Scroll down until you find the section shown above, click edit, uncheck the box, and hit the save button.

How do I fix an AWS S3 bucket policy and public permissions access denied error?

We are halfway there, and this is probably not your issue, but it is a good idea to make sure just in case.

It's always the tiny careless mistakes that give us the worst headaches.

2. Not Setting a permission policy for the bucket

Let me break it to you, in AWS, everything, and I mean absolutely everything requires permissions.

Permissions are excellent and help us build secure applications, but it can be an easy thing to forget and a bit weird as a beginner.

If you stay in the permissions tab, scroll down until you find the section below.

How do I fix an AWS S3 bucket policy and public permissions access denied error?

Hit edit, so we can start editing the policy.

How do I fix an AWS S3 bucket policy and public permissions access denied error?

Note that you can easily copy your bucket name (ARN), which you will need in a bit.

If anything, delete whatever you have in the editor and copy the code snippet below.

Let's get a better understanding of what this policy is doing.

Effect: what we want to do with our action (could also be deny)

Principal: Who can perform the action (*) means anyone, so its public

Action: What action we want to allow to be performed. GetObject allows read access

Resource: What S3 bucket’s path do we want this rule to be applied to.

/* means all routes in our bucket

Remember your bucket ARN right above the editor? Click the copy icon and replace assets.tudicuando.com with your bucket's ARN.

Hit save.

When you scroll up and see your bucket name, The Ddashobard should display a red badge.

How do I fix an AWS S3 bucket policy and public permissions access denied error?

Either way, upload an image and test its "publicness" by going to the properties tab (of the picture) and copying the Object URL.

How do I fix an AWS S3 bucket policy and public permissions access denied error?

Now paste it into your browser, and Viola! You have served an image.

How do I fix an AWS S3 bucket policy and public permissions access denied error?

That's it; your bucket is now officially public 😎 and ready to serve some awesome pics. 📸

If you want to learn more about different AWS services, follow me for future content where I share insight and tutorials while building a production-ready web app using AWS.

I am new to AWS. I am setting up an S3 bucket that I want to use to store media files for a Django App I am developing.

I am logged in as the person who created the AWS account, but when I click on the permissions tab and then try to edit the bucket policy I am getting a message that states "You don't have permissions to edit bucket policy".

I am following a guide which describes the configuration for Django setup, but my understanding is that the purpose of doing this is to allow public read access to the files. I was able to set the CORS policy without any problems.

I created an IAM user logged in as them and it still gives errors. That IAM user has permissions to all S3 Buckets. The error states "After you or your AWS administrator have updated your permissions to allow the s3:PutBucketPolicy action, choose Save changes."

I went to the policy applied to the bucket and it has this permission. Here is the JSON.

{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "s3:ListBucket" ], "Resource": "mybucketARN" }, { "Effect": "Allow", "Action": [ "s3:PutObject", "s3:GetObject" ], "Resource": "mybucketARN" } ] }

Why is my S3 bucket Access Denied?

If you're getting Access Denied errors on public read requests that are allowed, check the bucket's Amazon S3 Block Public Access settings. Review the S3 Block Public Access settings at both the account and bucket level. These settings can override permissions that allow public read access.

How do I enable public access to Amazon S3 bucket?

Resolution.
Open the Amazon S3 console..
From the list of buckets, choose the bucket with the objects that you want to update..
Navigate to the folder that contains the objects..
From the object list, select all the objects that you want to make public..
Choose Actions, and then choose Make public..

How do you attach policy to S3 bucket to give public access for object?

Sign in to the AWS Management Console and open the Amazon S3 console at https://console.aws.amazon.com/s3/ . In the Buckets list, choose the name of the bucket that you want to create a bucket policy for or whose bucket policy you want to edit. Choose Permissions. Under Bucket policy, choose Edit.

How do I fix 403 forbidden on AWS S3?

Resolution.
Check your permissions for s3:PutObject or s3:PutObjectAcl. Follow these steps: ... .
Ask for permission to use an AWS KMS key. ... .
Check the bucket policy for explicit deny statements. ... .
Disable S3 Block Public Access. ... .
Grant the root user permission to write objects. ... .
Delete service control policies for AWS Organizations..