SAM Doctor

ERROR REFERENCE

BucketAlreadyExists / BucketAlreadyOwnedByYou

The template declares an AWS::S3::Bucket with an explicit BucketName, and that name is already taken. Bucket names are globally unique across every AWS account, so the collision can be with a stranger's bucket — or with one your own account left behind.

WHAT IT MEANS

What this error means

FIX

How to fix it

  1. Prefer omitting BucketName entirely. CloudFormation then generates a unique name, and the collision class disappears. Reference the bucket by !Ref where its name is needed.
  2. For BucketAlreadyOwnedByYou: check whether a previous stack left the bucket behind before reusing the name — importing the existing bucket or deleting it deliberately are both better than fighting the collision. Look before deleting; leftover buckets often still hold artifacts.
  3. If the name must be fixed and branded, add a uniquifying component (account id or region as a suffix via !Sub), so each account and region gets its own name.

AUTOMATE THE TRIAGE

Diagnose this automatically

SAM Doctor recognizes both error codes and the resource-handler wording (high confidence), and keeps them distinct from invalid-name validation failures. Runs locally; no AWS access, no log upload.

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

RELATED