Skip to content

Commit

Permalink
fix(dynamoDB): make TableV2 taggable (#31867)
Browse files Browse the repository at this point in the history
### 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*
  • Loading branch information
5d authored Nov 2, 2024
1 parent d0b7bf2 commit 796c6d1
Show file tree
Hide file tree
Showing 16 changed files with 254 additions and 30 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,13 @@
"KeyId": "alias/aws/kinesis"
}
]
}
},
"Tags": [
{
"Key": "stage",
"Value": "IntegTest"
}
]
},
"UpdateReplacePolicy": "Retain",
"DeletionPolicy": "Retain"
Expand Down Expand Up @@ -148,6 +154,14 @@
"Region": "us-east-2",
"TableClass": "STANDARD_INFREQUENT_ACCESS",
"Tags": [
{
"Key": "stage",
"Value": "IntegTest"
},
{
"Key": "tagAspectKey",
"Value": "tagAspectValue"
},
{
"Key": "USE2ReplicaTagKey",
"Value": "USE2ReplicaTagValue"
Expand Down Expand Up @@ -184,6 +198,14 @@
"Region": "us-west-2",
"TableClass": "STANDARD",
"Tags": [
{
"Key": "stage",
"Value": "IntegTest"
},
{
"Key": "tagAspectKey",
"Value": "tagAspectValue"
},
{
"Key": "USW2ReplicaTagKey",
"Value": "USW2ReplicaTagValue"
Expand Down Expand Up @@ -231,6 +253,14 @@
"Region": "us-east-1",
"TableClass": "STANDARD_INFREQUENT_ACCESS",
"Tags": [
{
"Key": "stage",
"Value": "IntegTest"
},
{
"Key": "tagAspectKey",
"Value": "tagAspectValue"
},
{
"Key": "primaryTableTagKey",
"Value": "primaryTableTagValue"
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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

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

new TableV2(this, 'GlobalTable', {
const globalTable = new TableV2(this, 'GlobalTable', {
tableName: 'my-global-table',
partitionKey: { name: 'pk', type: AttributeType.STRING },
sortKey: { name: 'sk', type: AttributeType.NUMBER },
Expand Down Expand Up @@ -68,10 +68,13 @@ class TestStack extends Stack {
],
tags: [{ key: 'primaryTableTagKey', value: 'primaryTableTagValue' }],
});

Tags.of(globalTable).add('tagAspectKey', 'tagAspectValue');
}
}

const app = new App();
Tags.of(app).add('stage', 'IntegTest');
new IntegTest(app, 'aws-cdk-global-table-integ', {
testCases: [new TestStack(app, 'aws-cdk-global-table', { env: { region: 'us-east-1' } })],
regions: ['us-east-1'],
Expand Down
Loading

0 comments on commit 796c6d1

Please sign in to comment.