Fix "An error occurred (AccessDenied) when calling the PutObject operation" on AWS S3
An error occurred (AccessDenied) when calling the PutObject operation: Access Denied
- upload failed: ./build/index.html to s3://my-bucket/index.html An error occurred (AccessDenied) when calling the PutObject operation: Access Denied
- An error occurred (AccessDenied) when calling the PutObject operation: User: arn:aws:iam::123456789012:user/deploy is not authorized to perform: s3:PutObject on resource: "arn:aws:s3:::my-bucket/index.html" because no identity-based policy allows the s3:PutObject action
- botocore.exceptions.ClientError: An error occurred (AccessDenied) when calling the PutObject operation: Access Denied
- AccessDenied: User: arn:aws:sts::123456789012:assumed-role/lambda-role/fn is not authorized to perform: kms:GenerateDataKey on resource: arn:aws:kms:eu-west-3:123456789012:key/1a2b3c4d
- An error occurred (AccessDenied) when calling the ListObjectsV2 operation: Access Denied
The AWS identity in use is not allowed to write to this bucket, or a rule explicitly prevents it. First check who you are with aws sts get-caller-identity, then that the IAM policy allows s3:PutObject on arn:aws:s3:::my-bucket/* (with /*), and that no bucket policy, Block Public Access or KMS key blocks it.
What this error means
For each request, AWS evaluates every applicable policy: the user’s or role’s IAM policy, the bucket policy, organisation SCPs, the VPC endpoint policy, and for an encrypted object the KMS key policy. The request is only accepted if at least one policy allows it and none explicitly denies it. So AccessDenied can come from any of those layers. Recent messages are more precise: because no identity-based policy allows points to the IAM policy, with an explicit deny in a resource-based policy points to the bucket policy. A bare "Access Denied" means checking layer by layer.
Common causes
- Wrong identity: the CLI uses another profile (
AWS_PROFILE), leftoverAWS_ACCESS_KEY_IDvariables, or the instance role instead of the expected one. - Wrong resource in the IAM policy:
arn:aws:s3:::my-bucketis the bucket, objects arearn:aws:s3:::my-bucket/*;PutObjectneeds the latter. - Explicit deny in the bucket policy: required encryption, HTTPS (
aws:SecureTransport), VPC or source IP. - Public ACL blocked: upload with
--acl public-readwhile Block Public Access is enabled (the default). - KMS key: the bucket encrypts with a customer-managed key and the identity lacks
kms:GenerateDataKey(andkms:Decryptfor multipart uploads).
Step-by-step fix
-
Check which identity is used
Compare the displayed ARN with the user or role you granted rights to. Environment variables take precedence over
~/.aws/credentials.aws sts get-caller-identity aws configure list env | grep -E "^AWS_" aws sts get-caller-identity --profile deploy -
Fix the IAM policy
Grant
s3:PutObjecton the objects (/*) ands3:ListBucketon the bucket itself. Foraws s3 sync, both are needed, pluss3:DeleteObjectwith--delete.{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": ["s3:PutObject", "s3:GetObject", "s3:DeleteObject"], "Resource": "arn:aws:s3:::my-bucket/*" }, { "Effect": "Allow", "Action": "s3:ListBucket", "Resource": "arn:aws:s3:::my-bucket" } ] } -
Simulate the permission
The IAM simulator tells you whether the action is allowed by the identity’s policies, and which one blocks it. Replace the ARN with the one shown in step 1.
aws iam simulate-principal-policy \ --policy-source-arn arn:aws:iam::123456789012:user/deploy \ --action-names s3:PutObject \ --resource-arns "arn:aws:s3:::my-bucket/index.html" \ --query "EvaluationResults[].[EvalActionName,EvalDecision]" -
Read the bucket policy and Block Public Access
Look for an
"Effect": "Deny"and its conditions. If you upload with--acl public-read, drop the option: for a public site, prefer CloudFront with Origin Access Control over disabling Block Public Access.aws s3api get-bucket-policy --bucket my-bucket --query Policy --output text aws s3api get-public-access-block --bucket my-bucket aws s3api get-bucket-encryption --bucket my-bucket -
Allow the KMS key
If the bucket uses SSE-KMS with your own key, add these actions to the IAM policy and check that the key policy also allows the account or role.
{ "Effect": "Allow", "Action": ["kms:GenerateDataKey", "kms:Decrypt"], "Resource": "arn:aws:kms:eu-west-3:123456789012:key/1a2b3c4d-5e6f-7a8b-9c0d-1e2f3a4b5c6d" } -
Test the upload again
A small file is enough. IAM changes usually take effect within seconds.
echo test > /tmp/test.txt aws s3 cp /tmp/test.txt s3://my-bucket/test.txt
Did this fix work for you?
Confirm it in one click: it will rise for the next developers stuck on the same error.
Keep it from coming back
- Use one dedicated role per application or pipeline (OIDC for GitHub Actions) rather than shared long-lived access keys.
- Keep Block Public Access enabled and serve public files through CloudFront.
- Add
aws sts get-caller-identityat the start of your deployment scripts to see right away which identity is acting.
Frequently asked questions
I am an account administrator and still get AccessDenied, how?
An explicit Deny always wins, even over AdministratorAccess: it comes from the bucket policy, an organisation SCP, a VPC endpoint policy or the KMS key policy.
Why does PutObject work but GetObject fail on the same file?
Rights are per action: you also need s3:GetObject. With SSE-KMS, reading also requires kms:Decrypt.
What about "AccessControlListNotSupported: The bucket does not allow ACLs"?
The bucket uses the "Bucket owner enforced" object ownership (default since 2023), which disables ACLs. Remove --acl or ACL from your code and manage access with policies.
Useful tools for this error
More DevOps, servers & cloud errors
- Fix "upstream timed out (110: Connection timed out)" and 504 Gateway Time-out in Nginx
- Fix "nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)"
- Fix "413 Request Entity Too Large" (Nginx, PHP, Express, Cloudflare)
- Fix "Certbot failed to authenticate some domains" (Let’s Encrypt, Timeout during connect, acme-challenge 404)
- Fix "Resource not accessible by integration" in GitHub Actions
- Fix the 404 on refresh of a SPA on Vercel ("404: NOT_FOUND"), Netlify and Nginx
- Fix "The connection to the server localhost:8080 was refused" with kubectl