fix(cloudformation): generate AWS-style names for unnamed resources - #2536
Merged
Merged
Conversation
Resources whose name property a template leaves out were named after
their bare logical id, so two stacks from one template in the same
account (a stack set in two regions, dev and prod stacks) collided on
every such resource, and an unnamed S3 bucket got an invalid uppercase
name.
- New naming module: {StackName}-{LogicalId}-{SUFFIX} with a random
13-character suffix, truncated to each type's name limit and
lowercased where the type requires it; state machines and secrets
omit the stack name; nested stacks are named after their parent
- Applied across the provisioners that defaulted to the logical id or
to ad-hoc cfn-* / uuid names (RDS, Redshift/DocDB/Neptune clusters,
ElastiCache, SES, Route 53 and CloudFront caller references, ...)
- An unnamed FIFO queue gets the required .fifo ending
- Updates that leave the name out keep the resource's current name
instead of re-deriving one (CodeCommit, CodeArtifact, Elastic
Beanstalk, Amazon MQ, CloudWatch alarms, Backup plans, Organizations)
- e2e tests that asserted logical-id names now assert generated ones
…O topics - A resource re-created in place of an existing one (types without an in-place update, ECS task definitions) keeps the name it was generated, recovered from its physical id; resources named after their logical id by older builds keep that name too - An UpdateReplacePolicy-retained resource frees no name, so its replacement generates a new one - An unnamed FIFO topic gets the .fifo ending
…e legacy names
- Re-provisioning with UpdateReplacePolicy Retain stands in for an
in-place update too, so an unnamed resource keeps its name there
- Names older builds gave unnamed resources (cfn-* prefixes,
{LogicalId}-{8 hex}) are recognized and kept
…gacy names - A replacement whose old resource UpdateReplacePolicy retains gets a new name instead of overwriting the retained resource - Legacy names are recognized only in the name part of a physical id and only in the exact shapes older builds generated
- Trim a separator left at a truncation cut so names never carry '--' - Recover truncated FIFO names, generated with room for .fifo - Name limits for Route 53 and CloudFront caller references
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Resources whose name property a template leaves out were named after their bare logical id (
Queue,MyBucket, ...). Two stacks built from one template in the same account (dev and prod stacks, or one stack set deployed to two regions) collided on every such resource, and an unnamed S3 bucket got an invalid uppercase name.CloudFormation now generates names the way AWS does:
namingmodule:{StackName}-{LogicalId}-{SUFFIX}with a random 13-character suffix, truncated to each type's documented name limit (e.g. 32 for load balancers, 63 for buckets and RDS identifiers, 80 for queues), lowercased where the type requires it (S3, RDS, ElastiCache, ECR, Glue, OpenSearch, CodeArtifact domains),_instead of-where hyphens are invalid (Cognito identity pools, AppSync data sources). State machines and secrets are{LogicalId}-{SUFFIX}; nested stacks are{ParentStack}-{LogicalId}-{SUFFIX}.cfn-*/ uuid names: about 130 sites, including RDS instances and clusters, Redshift/DocDB/Neptune clusters, ElastiCache, SES, API Gateway keys, Route 53 and CloudFront caller references.FifoQueue/FifoTopic: true) get the required.fifoending; previously such a queue was silently created non-FIFO.cfn-*,{LogicalId}-{8 hex}) are recognized so an upgrade does not rename resources.UpdateReplacePolicy: Retaingives the new resource a fresh name, so it never overwrites the retained one.Test plan
cargo nextest run -p fakecloud-cloudformation --lib: 427 passed (naming shape, truncation, lowercase, separators, legacy names, update keeps name, re-provision keeps name, retained replacement renames, task definition revisions, FIFO endings)cloudformation_generated_names.rs: two stacks from one unnamed template get distinct names (queue, FIFO queue, lowercase bucket, topic); an update keeps the generated namecargo nextest run -p fakecloud-conformance --test cloudformation --test cloudcontrol --test apigatewaycargo clippy --workspace --all-targets -- -D warnings,cargo fmtSurface
website/content/docs/services/cloudformation.mdgains a "Generated names" entry; the gotcha about unnamed resources colliding is replaced by one about explicitly named resources being per account rather than per region.Summary by cubic
CloudFormation now generates AWS-style physical names for resources whose name properties are omitted instead of using logical IDs or ad-hoc names. This prevents collisions between stacks and produces valid service-specific names, including for S3 buckets.
Bug Fixes
{StackName}-{LogicalId}-{SUFFIX}with service-specific length, case, and separator rules; state machines and secrets use{LogicalId}-{SUFFIX}, while nested stacks include the parent stack name..fifosuffix to unnamed FIFO queues and topics.UpdateReplacePolicy: Retainpreserves the old resource.Coverage
Written for commit 282e2ab. Summary will update on new commits.