Skip to content
Latchkey

Serverless Framework "An error occurred: ... already exists" in CI

During deploy, CloudFormation tried to create a resource with a globally or account-unique name that already exists (an S3 bucket, a log group, an IAM role), and rejected it. Serverless surfaces the per-resource "already exists".

What this error means

serverless deploy fails with "An error occurred: <LogicalId> - <name> already exists" and the stack rolls back, commonly for S3 buckets, CloudWatch log groups, or named IAM roles.

serverless
Error:
An error occurred: ServerlessDeploymentBucket - my-service-bucket already exists

Common causes

A name collides with an existing resource

S3 bucket names are globally unique and log groups/roles are account-unique; a leftover resource from a prior deploy or another stack already owns the name.

An orphaned resource from a deleted stack

A previous stack was deleted but a resource (a retained log group or bucket) survived, blocking recreation.

How to fix it

Remove or rename the conflicting resource

  1. Identify the named resource in the error.
  2. Delete the orphaned resource, or change the name in serverless.yml.
  3. Re-deploy so creation no longer collides.
Terminal
aws logs delete-log-group --log-group-name /aws/lambda/my-service-dev-fn

Let Serverless manage the deployment bucket

Remove a hardcoded globally unique bucket name so Serverless generates a unique one.

serverless.yml
provider:
  deploymentBucket:
    # omit a fixed 'name:' so a unique bucket is generated

How to prevent it

  • Avoid hardcoding globally unique names like S3 buckets.
  • Clean up retained resources after deleting a stack.
  • Namespace resource names by stage to avoid cross-stack clashes.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →