Naming Conflict in AWS CDK v2.128: addRotationSingleUser Lambda Naming Collision Across Multiple Stacks with Identical Node IDs
- Dominant language
- TypeScript
- Stars
- 12.9k
- Forks
- 4.6k
- Avg merge
- 2d 3h
- Merged PRs (30d)
- 83
Description
### Describe the bug
### Bug Description
**Context**: The issue arises when creating a `ServerlessCluster` in AWS CDK, particularly when using the same logical ID (`node id`) for this resource in multiple CDK projects. This problem occurs even if these projects are deployed in the same AWS region.
**Problem**: Despite different `stackName`s being specified in each project, a naming conflict occurs for the `addRotationSingleUser` Lambda function associated with the `ServerlessCluster`. This leads to an error stating that the resource already exists.
**Root Cause**: It appears that the naming mechanism for the `addRotationSingleUser` Lambda function does not appropriately differentiate between the CDK stack ID (`node id`) and the `stackName`. This results in a naming collision, as the Lambda function's name is generated based on the `node id` only, without considering the unique `stackName` of each project.
**Expected Behavior**: The name for each `addRotationSingleUser` Lambda function should be unique across different stacks, especially when they have distinct `stackName`s. The naming convention should incorporate both the `stackName` and the `node id` to ensure uniqueness, avoiding conflicts across multiple CDK projects deployed in the same region.
### Expected Behavior
The new ServerlessCluster is in a different stack, so the rotation single user should not exist.
### Current Behavior
Deployment fails with a rotation single user resource already exists.
CREATE_FAILED | AWS::Lambda::Function | SecretsManagerRDSMySQLRotationSingleUser
testauroramysqlclusterRotationSingleUser3DBEDD21 already exists in stack arn:aws:cloudformation:XXXXXXX stack.
### Reproduction Steps
### Issue Summary
The Secrets Manager rotation single user is incorrectly named in two CDK projects. Both projects use "test" as the logical identifier but have different `stackName`s. They also use a shared construct library to create a Serverless Cluster.
### Project 1: Seattle
- **CDK Stack Creation**
```typescript
new cdk.Stack(app, "test", {
stackName: "cdk-seattle",
});
const auroraInstance = new ServerlessCluster(this, "aurora-mysql-cluster", { /* ... */ });
auroraInstance.addRotationSingleUser({
automaticallyAfter: Duration.days(30),
});
```
- **Generated Names**
- **Incorrect SecretsManagerRDSMySQLRotationSingleUser**: `testauroramysqlclusterRotationSingleUser3DBEDD21`
- **Correct SecretsManagerRDSMySQLRotationSingleUserRole**: `cdk-seattle-SecretsManagerRDSMySQLRot-2kTqohOcS6Lh`
### Project 2: Florida
- **CDK Stack Creation**
```typescript
new cdk.Stack(app, "test", {
stackName: "cdk-florida",
});
const auroraInstance = new ServerlessCluster(this, "aurora-mysql-cluster", { /* ... */ });
auroraInstance.addRotationSingleUser({
automaticallyAfter: Duration.days(30),
});
```
- **Generated Names**
- **Incorrect SecretsManagerRDSMySQLRotationSingleUser**: `testauroramysqlclusterRotationSingleUserDFBEDD21`
- **Correct SecretsManagerRDSMySQLRotationSingleUserRole**: `cdk-florida-SecretsManagerRDSMySQLRot-2GlqohOcS6Lh`
### Issue Description
- The rotation single user secret name should be based on the `stackName` rather than the logical identifier `test`.
- Correct naming should follow the pattern: `cdk-[stackName]auroramysqlclusterRotationSingleUser[UniqueID]`.
### Possible Solution
Use the stack name instead of the logical id for the lambda name.
### Additional Information/Context
_No response_
### CDK CLI Version
2.128
### Framework Version
3.431.0
### Node.js Version
v20.11.1
### OS
Ubuntu 23
### Language
TypeScript
### Language Version
Typescript 5.2.2
### Other information
_No response_
Contributor guide
Research direction
Start with the ServerlessCluster.addRotationSingleUser implementation and reproduce the issue using the two TypeScript stacks shown, keeping the logical identifier identical while changing stackName. The work is done when each generated rotation Lambda name is unique across the stacks and both deployments succeed without an existing-resource error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- aws, typescript
- Domain
- cloud, infrastructure
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100