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 个月前2748 查看次数
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 个月前

您未登录。 登录 发布回答。

一个好的回答可以清楚地解答问题和提供建设性反馈,并能促进提问者的职业发展。

回答问题的准则

相关内容