Why am I getting an access denied error when I open the link to an Amazon s3 object that I have access to?

I am new to aws..
I uploaded a image in the bucket

if i try to open the object url in browser im getting the following error.

Why am I getting an access denied error when I open the link to an Amazon s3 object that I have access to?

below are the bucket policies i have configured my bucket with


{
"Version": "2012-10-17",
"Id": "Policy1566555268319",
"Statement": [
{
"Sid": "Stmt1566555264845",
"Effect": "Allow",
"Principal": {
"AWS": "arn:aws:iam::497899159094:user/DevUser"
},
"Action": [
"s3:PutObject",
"s3:PutObjectAcl"
],
"Resource": "arn:aws:s3:::akirainfocombucket/*",
"Condition": {
"StringEquals": {
"s3:x-amz-acl": "public-read"
}
}
}
]
}

and Below are the CORS Configurations


<?xml version="1.0" encoding="UTF-8"?>
<CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
<CORSRule>
<AllowedOrigin>*</AllowedOrigin>
<AllowedMethod>GET</AllowedMethod>
<AllowedMethod>POST</AllowedMethod>
<AllowedMethod>PUT</AllowedMethod>
<MaxAgeSeconds>3000</MaxAgeSeconds>
<AllowedHeader>Authorization</AllowedHeader>
</CORSRule>
</CORSConfiguration>

The Block all public access is set to Off as suggested by the support team.

I want the object link to be accessible in the browser..(Read only)

need help to configure the Bucket ?


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.

Why am I getting an access denied error when I open the link to an Amazon s3 object that I have access to?

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

Why am I getting an access denied error when I open the link to an Amazon s3 object that I have access to?

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.

Why am I getting an access denied error when I open the link to an Amazon s3 object that I have access to?

Hit edit, so we can start editing the policy.

Why am I getting an access denied error when I open the link to an Amazon s3 object that I have access to?

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.

Why am I getting an access denied error when I open the link to an Amazon s3 object that I have access to?

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

Why am I getting an access denied error when I open the link to an Amazon s3 object that I have access to?

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

Why am I getting an access denied error when I open the link to an Amazon s3 object that I have access to?

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.

Why is my s3 URL Access Denied?

Short description. The URL to the Amazon S3 object doesn't include your user credentials, so the request to the object is anonymous. Amazon S3 returns an Access Denied error for anonymous requests to objects that aren't public.

Why am I getting an access denied error from the Amazon s3 console when I try to modify a bucket policy?

Short description. The "403 Access Denied" error can occur due to the following reasons: Your AWS Identity and Access Management (IAM) user or role doesn't have permissions for both s3:GetBucketPolicy and s3:PutBucketPolicy.

When accessing a s3 bucket you get 403 Forbidden error What does it mean?

The "403 Forbidden" error can occur due to the following reasons: Permissions are missing for s3:PutObject to add an object or s3:PutObjectAcl to modify the object's ACL. You don't have permission to use an AWS Key Management Service (AWS KMS) key. There is an explicit deny statement in the bucket policy.