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 個月前檢視次數 2764 次
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 個月前

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南