-
Notifications
You must be signed in to change notification settings - Fork 4.5k
dynamodb: TableV2 generates bad Logical ID #27062
Description
Describe the bug
When you declare a TableV2 construct, the table in the resulting CloudFormation template has the logical ID Resource with no appended hash value like other types of resources.
As a result, multiple TableV2's cannot be declared in the same stack as their IDs will conflict.
Expected Behavior
Declaring a TableV2 with construct ID DataStore should result in a template logical ID such as DataStore6B161152, and declaring multiple tables should be possible.
Current Behavior
The resulting logical ID is Resource. Declaring multiple tables results in this:
Error: There is already a Construct with name 'Resource' in MyTestStack
Reproduction Steps
export class MyTestStack extends Stack {
constructor(scope: Construct, id: string, props: StackProps) {
super(scope, id, props);
new ddb.TableV2(this, 'DataStore', {
partitionKey: {name: 'id', type: ddb.AttributeType.STRING}
});
new ddb.TableV2(this, 'AnotherTable', {
partitionKey: {name: 'id', type: ddb.AttributeType.STRING}
});
}
}
Possible Solution
I believe the cause of this bug is this line: https://github.com/aws/aws-cdk/blob/ffd4b7d7897c34b43bb5f80edb9c42024df98776/packages/aws-cdk-lib/aws-dynamodb/lib/table-v2.ts#L473C23-L473C23
The scope of the CfnGlobalTable resource should be this instead of scope
Additional Information/Context
No response
CDK CLI Version
2.95.0 (build cfa7e88)
Framework Version
No response
Node.js Version
18.15.0
OS
MacOS
Language
Typescript
Language Version
No response
Other information
No response