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.
Error:
An error occurred: ServerlessDeploymentBucket - my-service-bucket already existsCommon 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
- Identify the named resource in the error.
- Delete the orphaned resource, or change the name in serverless.yml.
- Re-deploy so creation no longer collides.
aws logs delete-log-group --log-group-name /aws/lambda/my-service-dev-fnLet Serverless manage the deployment bucket
Remove a hardcoded globally unique bucket name so Serverless generates a unique one.
provider:
deploymentBucket:
# omit a fixed 'name:' so a unique bucket is generatedHow 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.