Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dynamodb: TableV2 generates bad Logical ID #27062

Closed
roc13x opened this issue Sep 8, 2023 · 1 comment · Fixed by #27075
Closed

dynamodb: TableV2 generates bad Logical ID #27062

roc13x opened this issue Sep 8, 2023 · 1 comment · Fixed by #27075
Assignees
Labels
@aws-cdk/aws-dynamodb Related to Amazon DynamoDB bug This issue is a bug. in-progress This issue is being actively worked on. p1

Comments

@roc13x
Copy link

roc13x commented Sep 8, 2023

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

@roc13x roc13x added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Sep 8, 2023
@github-actions github-actions bot added the @aws-cdk/aws-dynamodb Related to Amazon DynamoDB label Sep 8, 2023
@colifran colifran self-assigned this Sep 8, 2023
@colifran colifran added in-progress This issue is being actively worked on. p1 and removed needs-triage This issue or PR still needs to be triaged. labels Sep 8, 2023
@mergify mergify bot closed this as completed in #27075 Sep 8, 2023
mergify bot pushed a commit that referenced this issue Sep 8, 2023
…is instead of scope (#27075)

`CfnGlobalTable` in the constructor of `TableV2` was incorrectly using `scope` instead of `this`. As a result, `TableV2` was not generating correct logical IDs.

Closes #27062

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
@github-actions
Copy link

github-actions bot commented Sep 8, 2023

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

MrArnoldPalmer pushed a commit that referenced this issue Sep 8, 2023
…is instead of scope (#27075)

`CfnGlobalTable` in the constructor of `TableV2` was incorrectly using `scope` instead of `this`. As a result, `TableV2` was not generating correct logical IDs.

Closes #27062

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
mikewrighton pushed a commit that referenced this issue Sep 14, 2023
…is instead of scope (#27075)

`CfnGlobalTable` in the constructor of `TableV2` was incorrectly using `scope` instead of `this`. As a result, `TableV2` was not generating correct logical IDs.

Closes #27062

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-dynamodb Related to Amazon DynamoDB bug This issue is a bug. in-progress This issue is being actively worked on. p1
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants