fix: skip CDK-managed singletons in ResourcePrefixAspect#1702
Merged
toddhainsworth merged 2 commits intoJun 5, 2026
Conversation
ResourcePrefixAspect pinned deterministic physical names onto CDK-managed singleton/framework resources (BucketDeployment handler, LogRetention, S3AutoDeleteObjects, cr.Provider lambdas). That removed CloudFormation's random-suffix orphan-avoidance, so a failed deploy could orphan the service-created /aws/lambda/<fn> log group and wedge every subsequent deploy on 'AWS::Logs::LogGroup ... already exists'. Extract the shared singleton path-fragment list and isCdkManagedSingleton helper into lib/cdk-managed-singletons.ts, consumed by both MicroserviceChecks and ResourcePrefixAspect, and skip these resources during prefixing.
The path-fragment skip already covers the singleton handler's nested IAM service role and log group, resolving the cross-stack IAM role collision (account-global RoleName identical across stacks) alongside the log group orphan collision. Add a regression test asserting the role keeps its CloudFormation-generated name, and expand the README and changeset to document both failure modes.
kai-nguyen-aligent
approved these changes
Jun 5, 2026
kai-nguyen-aligent
left a comment
Contributor
There was a problem hiding this comment.
Wow, you're faster than me, Todd. I had this in my list but you beat me ❤️
AdamJHall
approved these changes
Jun 5, 2026
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
ResourcePrefixAspectassigned deterministic, logical-id-derived physical names to CDK-managed singleton/framework resources — notably theBucketDeploymentcustom-resource handler and its nested IAM service role and log group. Because these singletons share a fixed logical id across every stack, the prefixed name collapses to a single value per prefix scope, removing the per-stack and per-creation uniqueness CloudFormation normally provides. This caused two distinct deploy failures.Failure mode 1 (severe): cross-stack IAM role collision
Two
BucketDeployment-using stacks in the same stage/brand received the same account-globalRoleName, so the second stack failed:Version-independent (the aspect has set explicit
RoleName/FunctionNameon these singletons since ≥ 0.5.7).Failure mode 2: orphaned
/aws/lambdaLogGroup collision on retryThe handler runs during deploy; the Lambda service auto-creates
/aws/lambda/<fn>. A failed/rolled-back deploy orphans that group (CFN never owned it, socdk destroydoesn't clear it), and the deterministic function name regenerates the identical name on retry:Surfaced after
0.6.1(which correctly stopped mangling/aws/log group names — that fix exposed the latent collision).Fix
isCdkManagedSingletonhelper into a new internallib/cdk-managed-singletons.ts— single source of truth.MicroserviceChecksrefactored to consume it (behaviour-preserving).ResourcePrefixAspect.visit()skips these resources, leaving their physical names CloudFormation-generated. The path-includesskip covers the handler and its nested children (IAM service role, log group), resolving both failure modes at once. Keeps the0.6.1/aws/log-group fix intact.Covered singletons:
Custom::CDKBucketDeployment,LogRetention,Custom::S3AutoDeleteObjects,cr.Provider(AWS679f53fac002430cb0da5b7982bd2287).Testing
BucketDeploymenthandler lambda, its IAM service role, and theS3AutoDeleteObjectshandler all keep CloudFormation-generated names.myapp-CustomCDKBucketDeployment8693-....build+test(58 passed) +lintall green.Changeset
@aligent/cdk-aspects: patch