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.

질문됨 8달 전2758회 조회
2개 답변
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
전문가
답변함 8달 전
  • 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
답변함 3달 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠