Last updated: Feb 26, 2024
Reading time·3 min
The S3 error "(AccessDenied) when calling the PutObject operation" occurs when we try to upload a file to an S3 bucket without having the necessary permissions.
In order to solve the "(AccessDenied) when calling the PutObject operation" error:
Permissions
tab and scroll down to the
Block public access (bucket settings)
section.acl
to public-read
, verify that creating new public ACLs is not blocked
in your bucket. Save and confirm the changes.On the same page, scroll down to the Bucket Policy
section and verify that
your bucket policy does not Deny
the PutObject
action or have a
Condition
that prevents you from uploading files, e.g. an IP restriction.
Verify that you are not misspelling the name of the bucket when uploading
files. E.g. in this example, I try to upload a file to a bucket named
hello
. Since I don't own this bucket, I get the "(AccessDenied) when
calling the PutObject operation" error.
PutObject
permissions and verifying
that it has the following actions allowed:Make sure to replace the YOUR_BUCKET
placeholder with the name of your
S3 bucket.
Don't attach this policy as a bucket policy.
Rather attach it to the user who is trying to upload files to the S3 bucket or to the corresponding role (e.g. of a Lambda function or EC2 instance).
{ "Version": "2012-10-17", "Statement": [ { "Action": [ "s3:PutObject", "s3:PutObjectAcl", "s3:GetObject", "s3:GetObjectAcl", "s3:AbortMultipartUpload" ], "Resource": [ "arn:aws:s3:::YOUR_BUCKET", "arn:aws:s3:::YOUR_BUCKET/*" ], "Effect": "Allow" } ] }
Once the policy is attached to the IAM entity, you will be able to upload files to your S3 bucket.
You can learn more about the related topics by checking out the following tutorials: