ClientError at url An error occurred (403) when calling the HeadObject operation: Forbidden

0

I am using s3 bucket in my django project and while submitting a form from local server the files which are sent from the form is successfully uploaded in the s3 bucket. After deploying that project in the versel I am unable to upload the files through forms and while I am submitting the form It is showing "botocore.exceptions.ClientError: An error occurred (403) when calling the HeadObject operation: Forbidden". I am a student and unable have gone through each and every solution in the net. Anyone please give me a solution and Elaborate the solution and guide me proper way that I can solve this.

asked 8 months ago2390 views
2 Answers
0

You need to make sure that whichever IAM user/role is being used in this application, that IAM user/role has following permissions at least:

Actions:

s3:PutObject

s3:GetObject

Resource: arn:aws:s3:::<bucket_name>/<folder>/* or arn:aws:s3:::<bucket_name>/* <-- Based on your needs

Action: s3:listBucket

Resources: arn:aws:s3:::<bucket_name>

Policy that needs to be added to your IAM user/role would look like as below:

{
    "Version": "2012-10-17",
    "Statement": [
    	    {
	    	    "Sid": "VisualEditor0",
		    "Effect": "Allow",
		    "Action": "s3:ListBucket",
		    "Resource": "arn:aws:s3:::<bucket_name>"
	    },
	    {
		    "Sid": "VisualEditor1",
		    "Effect": "Allow",
		    "Action": [
                             "s3:GetObject",
                             "s3:PutObject"
                            ]
		    "Resource": "arn:aws:s3:::<bucket_name>/*"
	    }
    ]
}

Hope this helps.

Comment here if you have additional questions, happy to help.

Abhishek

profile pictureAWS
EXPERT
answered 8 months ago
  • Sir your solution is not working. It is throwing the same error

  • Can you please add snapshot of your role permissions which is being used by this application.

  • I have created the (inline)policy given by you named "joyguruerpolicy" in the IAM user. and there bucket is private and I have not set any bucket policies and cors policy also. I am attaching a google drive link here that you can access the snapshots.link-https://drive.google.com/drive/folders/1euVNMOBMx74ueLASihHJWkLr47ayPxIl

0

Hi, I'm facing the same problem secondabhi, I'm create a Django project, deploy in an EC2 and it was working perfectly

But now, I'm trying to change somethings in my project and I'm receiving this same error

I've set this bucket policy as bellow and I try your too, but no one works

{ "Version": "2012-10-17", "Statement": [ { "Sid": "PublicReadGetObject", "Effect": "Allow", "Principal": "", "Action": "s3:", "Resource": "arn:aws:s3:::ecommerces3/*" } ] }

I'm really stuck on this one

vitor
answered 3 months ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions