SAM Doctor

ERROR REFERENCE

S3 error: Access Denied (deployment bucket)

sam deploy failed talking to its artifact bucket: either the upload was rejected, or CloudFormation could not read the uploaded template and zip back out of S3. The two directions fail for different identities, and the fix depends on which one you have.

WHAT IT MEANS

What this error means

Common causes, roughly in order of frequency:

FIX

How to fix it

  1. Separate the directions (read-only):
    aws s3api head-object --bucket my-deploy-bucket --key path/from/the/error
    If your credentials can read the object, the upload worked and the failure is CloudFormation's readback — look at bucket policy and KMS. If head-object is denied too, the problem is your deploy identity's access.
  2. Catch the wrong-Region bucket:
    aws s3api get-bucket-location --bucket my-deploy-bucket
    The bucket's Region must match the Region you deploy to; SAM's managed bucket (--resolve-s3) avoids this class entirely.
  3. Check encryption:
    aws s3api get-bucket-encryption --bucket my-deploy-bucket
    SSE-KMS buckets need the deploy identity to hold key permissions alongside the S3 permissions.
  4. Confirm ownership before touching policy. If the bucket belongs to another account, coordinate rather than widening a policy you do not own.

AUTOMATE THE TRIAGE

Diagnose this automatically

SAM Doctor recognizes both directions (high confidence) and keeps IAM-worded denials with the IAM rules, which name the policy layer instead. Runs locally; no AWS access, no log upload.

python -m pip install sam-doctor
sam-doctor diagnose deployment.log --format markdown

RELATED