Skip to content
Latchkey

CloudFormation "CREATE_FAILED ... already exists" in CI

CloudFormation tried to create a resource whose physical name is already taken (an existing S3 bucket, IAM role, or log group), so it marks the resource CREATE_FAILED and rolls the stack back.

What this error means

A stack event shows status CREATE_FAILED with a reason like "<name> already exists" or "Resource of type ... with identifier ... already exists", and the stack ends in ROLLBACK_COMPLETE.

CloudFormation
CREATE_FAILED   AWS::S3::Bucket   AssetsBucket
Resource handler returned message: "my-app-assets already exists"
(Service: S3, Status Code: 409, Request ID: ...)

Common causes

A hardcoded name collides with an existing resource

The template sets an explicit BucketName or RoleName that already exists in the account or globally (S3 names are global), so creation fails.

A previous failed deploy left the resource behind

A resource was created outside CloudFormation, or a prior stack was deleted without removing it, so the new create hits a name clash.

How to fix it

Let CloudFormation generate the name

  1. Remove the explicit name property so CloudFormation assigns a unique physical ID.
  2. If a stable name is required, make it unique per stack with !Sub and the stack name.
  3. Redeploy so the create no longer collides.
template.yml
Resources:
  AssetsBucket:
    Type: AWS::S3::Bucket
    Properties:
      BucketName: !Sub '${AWS::StackName}-assets'

Import or delete the orphaned resource

If the resource already exists and should be managed by this stack, import it; otherwise delete the orphan, then redeploy.

Terminal
aws cloudformation create-change-set \
  --stack-name my-app --change-set-type IMPORT \
  --resources-to-import file://import.json --template-body file://template.yml

How to prevent it

  • Avoid hardcoded physical names; let CloudFormation generate them.
  • Scope explicit names per stack with the stack name prefix.
  • Clean up resources created outside the stack before deploying.

Frequently asked questions

What causes ""already exists in stack""?
The template sets an explicit BucketName or RoleName that already exists in the account or globally (S3 names are global), so creation fails.
How do I fix "already exists in stack"?
Let CloudFormation generate the name

Related guides

References

Latchkey auto-heals failures like this one - detected, fixed, and retried without you. Start free → 30-day trial · No credit card