Skip to content

Commit 796c6d1

Browse files
authored
fix(dynamoDB): make TableV2 taggable (#31867)
### Issue # (if applicable) Closes #30631 ### Reason for this change The [`AWS::DynamoDB::GlobalTable`](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-dynamodb-globaltable.html) resource does not natively support tags. However, at the L2 level (`TableV2`), the [`tags`](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_dynamodb.TableV2.html#tags) option is available when creating this resource, which may give customers the impression that it is taggable. When customers apply tags using the aspect at the `TableV2` level, it’s likely they intend to tag all replicas, as each replica has its own `tags` property as well. This behavior also aligns with the related [construct documentation](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_dynamodb.TableV2.html#tags). ### Description of changes - Enable tagging for `TableV2` - If a tag key is defined in the replica `tags` properties, it will take precedence over the `TagAspect` for that key, as it is more specific. - Keep the `tags` property behavior in `TableV2` - Update the description doc on it to reflect that it only applies to the default replica table ### Description of how you validated changes - added new unit test cases - deployed related integration test cases ### Checklist - [x] My code adheres to the [CONTRIBUTING GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and [DESIGN GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md) ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent d0b7bf2 commit 796c6d1

16 files changed

+254
-30
lines changed

packages/@aws-cdk-testing/framework-integ/test/aws-dynamodb/test/integ.dynamodb-v2.ondemand.js.snapshot/aws-cdk-global-table.assets.json

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk-testing/framework-integ/test/aws-dynamodb/test/integ.dynamodb-v2.ondemand.js.snapshot/awscdkglobaltableintegDefaultTestDeployAssertA2A9E81F.assets.json

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk-testing/framework-integ/test/aws-dynamodb/test/integ.dynamodb-v2.ondemand.js.snapshot/cdk.out

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk-testing/framework-integ/test/aws-dynamodb/test/integ.dynamodb-v2.ondemand.js.snapshot/integ.json

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk-testing/framework-integ/test/aws-dynamodb/test/integ.dynamodb-v2.ondemand.js.snapshot/manifest.json

+3-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk-testing/framework-integ/test/aws-dynamodb/test/integ.dynamodb-v2.ondemand.js.snapshot/tree.json

+3-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk-testing/framework-integ/test/aws-dynamodb/test/integ.table-v2-global.js.snapshot/aws-cdk-global-table.assets.json

+3-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk-testing/framework-integ/test/aws-dynamodb/test/integ.table-v2-global.js.snapshot/aws-cdk-global-table.template.json

+31-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,13 @@
1616
"KeyId": "alias/aws/kinesis"
1717
}
1818
]
19-
}
19+
},
20+
"Tags": [
21+
{
22+
"Key": "stage",
23+
"Value": "IntegTest"
24+
}
25+
]
2026
},
2127
"UpdateReplacePolicy": "Retain",
2228
"DeletionPolicy": "Retain"
@@ -148,6 +154,14 @@
148154
"Region": "us-east-2",
149155
"TableClass": "STANDARD_INFREQUENT_ACCESS",
150156
"Tags": [
157+
{
158+
"Key": "stage",
159+
"Value": "IntegTest"
160+
},
161+
{
162+
"Key": "tagAspectKey",
163+
"Value": "tagAspectValue"
164+
},
151165
{
152166
"Key": "USE2ReplicaTagKey",
153167
"Value": "USE2ReplicaTagValue"
@@ -184,6 +198,14 @@
184198
"Region": "us-west-2",
185199
"TableClass": "STANDARD",
186200
"Tags": [
201+
{
202+
"Key": "stage",
203+
"Value": "IntegTest"
204+
},
205+
{
206+
"Key": "tagAspectKey",
207+
"Value": "tagAspectValue"
208+
},
187209
{
188210
"Key": "USW2ReplicaTagKey",
189211
"Value": "USW2ReplicaTagValue"
@@ -231,6 +253,14 @@
231253
"Region": "us-east-1",
232254
"TableClass": "STANDARD_INFREQUENT_ACCESS",
233255
"Tags": [
256+
{
257+
"Key": "stage",
258+
"Value": "IntegTest"
259+
},
260+
{
261+
"Key": "tagAspectKey",
262+
"Value": "tagAspectValue"
263+
},
234264
{
235265
"Key": "primaryTableTagKey",
236266
"Value": "primaryTableTagValue"

packages/@aws-cdk-testing/framework-integ/test/aws-dynamodb/test/integ.table-v2-global.js.snapshot/awscdkglobaltableintegDefaultTestDeployAssertA2A9E81F.assets.json

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk-testing/framework-integ/test/aws-dynamodb/test/integ.table-v2-global.js.snapshot/cdk.out

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk-testing/framework-integ/test/aws-dynamodb/test/integ.table-v2-global.js.snapshot/integ.json

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk-testing/framework-integ/test/aws-dynamodb/test/integ.table-v2-global.js.snapshot/manifest.json

+32-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk-testing/framework-integ/test/aws-dynamodb/test/integ.table-v2-global.js.snapshot/tree.json

+33-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk-testing/framework-integ/test/aws-dynamodb/test/integ.table-v2-global.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { IntegTest } from '@aws-cdk/integ-tests-alpha';
2-
import { App, RemovalPolicy, Stack, StackProps } from 'aws-cdk-lib';
2+
import { App, RemovalPolicy, Stack, StackProps, Tags } from 'aws-cdk-lib';
33
import { AttributeType, Billing, Capacity, TableV2, TableClass, TableEncryptionV2 } from 'aws-cdk-lib/aws-dynamodb';
44
import { Stream } from 'aws-cdk-lib/aws-kinesis';
55
import { Construct } from 'constructs';
@@ -10,7 +10,7 @@ class TestStack extends Stack {
1010

1111
const stream = new Stream(this, 'Stream');
1212

13-
new TableV2(this, 'GlobalTable', {
13+
const globalTable = new TableV2(this, 'GlobalTable', {
1414
tableName: 'my-global-table',
1515
partitionKey: { name: 'pk', type: AttributeType.STRING },
1616
sortKey: { name: 'sk', type: AttributeType.NUMBER },
@@ -68,10 +68,13 @@ class TestStack extends Stack {
6868
],
6969
tags: [{ key: 'primaryTableTagKey', value: 'primaryTableTagValue' }],
7070
});
71+
72+
Tags.of(globalTable).add('tagAspectKey', 'tagAspectValue');
7173
}
7274
}
7375

7476
const app = new App();
77+
Tags.of(app).add('stage', 'IntegTest');
7578
new IntegTest(app, 'aws-cdk-global-table-integ', {
7679
testCases: [new TestStack(app, 'aws-cdk-global-table', { env: { region: 'us-east-1' } })],
7780
regions: ['us-east-1'],

0 commit comments

Comments
 (0)