diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-dynamodb/test/integ.dynamodb-v2.ondemand.js.snapshot/aws-cdk-global-table.assets.json b/packages/@aws-cdk-testing/framework-integ/test/aws-dynamodb/test/integ.dynamodb-v2.ondemand.js.snapshot/aws-cdk-global-table.assets.json index aa94a2c7845ca..edf92583f5036 100644 --- a/packages/@aws-cdk-testing/framework-integ/test/aws-dynamodb/test/integ.dynamodb-v2.ondemand.js.snapshot/aws-cdk-global-table.assets.json +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-dynamodb/test/integ.dynamodb-v2.ondemand.js.snapshot/aws-cdk-global-table.assets.json @@ -1,5 +1,5 @@ { - "version": "36.0.0", + "version": "38.0.1", "files": { "cc5278f2745ed14e48839e10ba3e84d52a026101a039e164e937d90f16b69c34": { "source": { diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-dynamodb/test/integ.dynamodb-v2.ondemand.js.snapshot/awscdkglobaltableintegDefaultTestDeployAssertA2A9E81F.assets.json b/packages/@aws-cdk-testing/framework-integ/test/aws-dynamodb/test/integ.dynamodb-v2.ondemand.js.snapshot/awscdkglobaltableintegDefaultTestDeployAssertA2A9E81F.assets.json index 0a9ffc385b09a..a01b555c8d324 100644 --- a/packages/@aws-cdk-testing/framework-integ/test/aws-dynamodb/test/integ.dynamodb-v2.ondemand.js.snapshot/awscdkglobaltableintegDefaultTestDeployAssertA2A9E81F.assets.json +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-dynamodb/test/integ.dynamodb-v2.ondemand.js.snapshot/awscdkglobaltableintegDefaultTestDeployAssertA2A9E81F.assets.json @@ -1,5 +1,5 @@ { - "version": "36.0.0", + "version": "38.0.1", "files": { "21fbb51d7b23f6a6c262b46a9caee79d744a3ac019fd45422d988b96d44b2a22": { "source": { diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-dynamodb/test/integ.dynamodb-v2.ondemand.js.snapshot/cdk.out b/packages/@aws-cdk-testing/framework-integ/test/aws-dynamodb/test/integ.dynamodb-v2.ondemand.js.snapshot/cdk.out index 1f0068d32659a..c6e612584e352 100644 --- a/packages/@aws-cdk-testing/framework-integ/test/aws-dynamodb/test/integ.dynamodb-v2.ondemand.js.snapshot/cdk.out +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-dynamodb/test/integ.dynamodb-v2.ondemand.js.snapshot/cdk.out @@ -1 +1 @@ -{"version":"36.0.0"} \ No newline at end of file +{"version":"38.0.1"} \ No newline at end of file diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-dynamodb/test/integ.dynamodb-v2.ondemand.js.snapshot/integ.json b/packages/@aws-cdk-testing/framework-integ/test/aws-dynamodb/test/integ.dynamodb-v2.ondemand.js.snapshot/integ.json index 15437c63539c9..2aacd3080724d 100644 --- a/packages/@aws-cdk-testing/framework-integ/test/aws-dynamodb/test/integ.dynamodb-v2.ondemand.js.snapshot/integ.json +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-dynamodb/test/integ.dynamodb-v2.ondemand.js.snapshot/integ.json @@ -1,5 +1,5 @@ { - "version": "36.0.0", + "version": "38.0.1", "testCases": { "aws-cdk-global-table-integ/DefaultTest": { "stacks": [ diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-dynamodb/test/integ.dynamodb-v2.ondemand.js.snapshot/manifest.json b/packages/@aws-cdk-testing/framework-integ/test/aws-dynamodb/test/integ.dynamodb-v2.ondemand.js.snapshot/manifest.json index f36374c4697b1..b5799752cf772 100644 --- a/packages/@aws-cdk-testing/framework-integ/test/aws-dynamodb/test/integ.dynamodb-v2.ondemand.js.snapshot/manifest.json +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-dynamodb/test/integ.dynamodb-v2.ondemand.js.snapshot/manifest.json @@ -1,5 +1,5 @@ { - "version": "36.0.0", + "version": "38.0.1", "artifacts": { "aws-cdk-global-table.assets": { "type": "cdk:asset-manifest", @@ -16,6 +16,7 @@ "templateFile": "aws-cdk-global-table.template.json", "terminationProtection": false, "validateOnSynth": false, + "notificationArns": [], "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-deploy-role-${AWS::AccountId}-us-east-1", "cloudFormationExecutionRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-cfn-exec-role-${AWS::AccountId}-us-east-1", "stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-us-east-1/cc5278f2745ed14e48839e10ba3e84d52a026101a039e164e937d90f16b69c34.json", @@ -90,6 +91,7 @@ "templateFile": "awscdkglobaltableintegDefaultTestDeployAssertA2A9E81F.template.json", "terminationProtection": false, "validateOnSynth": false, + "notificationArns": [], "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-deploy-role-${AWS::AccountId}-${AWS::Region}", "cloudFormationExecutionRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-cfn-exec-role-${AWS::AccountId}-${AWS::Region}", "stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/21fbb51d7b23f6a6c262b46a9caee79d744a3ac019fd45422d988b96d44b2a22.json", diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-dynamodb/test/integ.dynamodb-v2.ondemand.js.snapshot/tree.json b/packages/@aws-cdk-testing/framework-integ/test/aws-dynamodb/test/integ.dynamodb-v2.ondemand.js.snapshot/tree.json index 963c19fb401dd..ff85fbcbd863f 100644 --- a/packages/@aws-cdk-testing/framework-integ/test/aws-dynamodb/test/integ.dynamodb-v2.ondemand.js.snapshot/tree.json +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-dynamodb/test/integ.dynamodb-v2.ondemand.js.snapshot/tree.json @@ -231,7 +231,7 @@ } }, "constructInfo": { - "fqn": "aws-cdk-lib.aws_dynamodb.TableBaseV2", + "fqn": "aws-cdk-lib.aws_dynamodb.TableV2", "version": "0.0.0" } }, @@ -270,7 +270,7 @@ "path": "aws-cdk-global-table-integ/DefaultTest/Default", "constructInfo": { "fqn": "constructs.Construct", - "version": "10.3.0" + "version": "10.4.2" } }, "DeployAssert": { @@ -316,7 +316,7 @@ "path": "Tree", "constructInfo": { "fqn": "constructs.Construct", - "version": "10.3.0" + "version": "10.4.2" } } }, diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-dynamodb/test/integ.table-v2-global.js.snapshot/aws-cdk-global-table.assets.json b/packages/@aws-cdk-testing/framework-integ/test/aws-dynamodb/test/integ.table-v2-global.js.snapshot/aws-cdk-global-table.assets.json index 419f067b36e9e..929f0476cdfd0 100644 --- a/packages/@aws-cdk-testing/framework-integ/test/aws-dynamodb/test/integ.table-v2-global.js.snapshot/aws-cdk-global-table.assets.json +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-dynamodb/test/integ.table-v2-global.js.snapshot/aws-cdk-global-table.assets.json @@ -1,7 +1,7 @@ { - "version": "36.0.0", + "version": "38.0.1", "files": { - "a38411fa5a0afe5343485b65f2c16b2b258cbf8f67e1bf8dc53f06668c3b91d2": { + "f76e4db697eb7d6e297e40f4bafd35a109a7849082124cc1946d6efb31becfbd": { "source": { "path": "aws-cdk-global-table.template.json", "packaging": "file" @@ -9,7 +9,7 @@ "destinations": { "current_account-us-east-1": { "bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-us-east-1", - "objectKey": "a38411fa5a0afe5343485b65f2c16b2b258cbf8f67e1bf8dc53f06668c3b91d2.json", + "objectKey": "f76e4db697eb7d6e297e40f4bafd35a109a7849082124cc1946d6efb31becfbd.json", "region": "us-east-1", "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-us-east-1" } diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-dynamodb/test/integ.table-v2-global.js.snapshot/aws-cdk-global-table.template.json b/packages/@aws-cdk-testing/framework-integ/test/aws-dynamodb/test/integ.table-v2-global.js.snapshot/aws-cdk-global-table.template.json index 5c42c0eccbdd0..8fda8662e31e9 100644 --- a/packages/@aws-cdk-testing/framework-integ/test/aws-dynamodb/test/integ.table-v2-global.js.snapshot/aws-cdk-global-table.template.json +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-dynamodb/test/integ.table-v2-global.js.snapshot/aws-cdk-global-table.template.json @@ -16,7 +16,13 @@ "KeyId": "alias/aws/kinesis" } ] - } + }, + "Tags": [ + { + "Key": "stage", + "Value": "IntegTest" + } + ] }, "UpdateReplacePolicy": "Retain", "DeletionPolicy": "Retain" @@ -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" @@ -184,6 +198,14 @@ "Region": "us-west-2", "TableClass": "STANDARD", "Tags": [ + { + "Key": "stage", + "Value": "IntegTest" + }, + { + "Key": "tagAspectKey", + "Value": "tagAspectValue" + }, { "Key": "USW2ReplicaTagKey", "Value": "USW2ReplicaTagValue" @@ -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" diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-dynamodb/test/integ.table-v2-global.js.snapshot/awscdkglobaltableintegDefaultTestDeployAssertA2A9E81F.assets.json b/packages/@aws-cdk-testing/framework-integ/test/aws-dynamodb/test/integ.table-v2-global.js.snapshot/awscdkglobaltableintegDefaultTestDeployAssertA2A9E81F.assets.json index 0a9ffc385b09a..a01b555c8d324 100644 --- a/packages/@aws-cdk-testing/framework-integ/test/aws-dynamodb/test/integ.table-v2-global.js.snapshot/awscdkglobaltableintegDefaultTestDeployAssertA2A9E81F.assets.json +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-dynamodb/test/integ.table-v2-global.js.snapshot/awscdkglobaltableintegDefaultTestDeployAssertA2A9E81F.assets.json @@ -1,5 +1,5 @@ { - "version": "36.0.0", + "version": "38.0.1", "files": { "21fbb51d7b23f6a6c262b46a9caee79d744a3ac019fd45422d988b96d44b2a22": { "source": { diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-dynamodb/test/integ.table-v2-global.js.snapshot/cdk.out b/packages/@aws-cdk-testing/framework-integ/test/aws-dynamodb/test/integ.table-v2-global.js.snapshot/cdk.out index 1f0068d32659a..c6e612584e352 100644 --- a/packages/@aws-cdk-testing/framework-integ/test/aws-dynamodb/test/integ.table-v2-global.js.snapshot/cdk.out +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-dynamodb/test/integ.table-v2-global.js.snapshot/cdk.out @@ -1 +1 @@ -{"version":"36.0.0"} \ No newline at end of file +{"version":"38.0.1"} \ No newline at end of file diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-dynamodb/test/integ.table-v2-global.js.snapshot/integ.json b/packages/@aws-cdk-testing/framework-integ/test/aws-dynamodb/test/integ.table-v2-global.js.snapshot/integ.json index 15437c63539c9..2aacd3080724d 100644 --- a/packages/@aws-cdk-testing/framework-integ/test/aws-dynamodb/test/integ.table-v2-global.js.snapshot/integ.json +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-dynamodb/test/integ.table-v2-global.js.snapshot/integ.json @@ -1,5 +1,5 @@ { - "version": "36.0.0", + "version": "38.0.1", "testCases": { "aws-cdk-global-table-integ/DefaultTest": { "stacks": [ diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-dynamodb/test/integ.table-v2-global.js.snapshot/manifest.json b/packages/@aws-cdk-testing/framework-integ/test/aws-dynamodb/test/integ.table-v2-global.js.snapshot/manifest.json index fe3ce6aaeb327..cdfdbcd507e22 100644 --- a/packages/@aws-cdk-testing/framework-integ/test/aws-dynamodb/test/integ.table-v2-global.js.snapshot/manifest.json +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-dynamodb/test/integ.table-v2-global.js.snapshot/manifest.json @@ -1,5 +1,5 @@ { - "version": "36.0.0", + "version": "38.0.1", "artifacts": { "aws-cdk-global-table.assets": { "type": "cdk:asset-manifest", @@ -15,10 +15,14 @@ "properties": { "templateFile": "aws-cdk-global-table.template.json", "terminationProtection": false, + "tags": { + "stage": "IntegTest" + }, "validateOnSynth": false, + "notificationArns": [], "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-deploy-role-${AWS::AccountId}-us-east-1", "cloudFormationExecutionRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-cfn-exec-role-${AWS::AccountId}-us-east-1", - "stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-us-east-1/a38411fa5a0afe5343485b65f2c16b2b258cbf8f67e1bf8dc53f06668c3b91d2.json", + "stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-us-east-1/f76e4db697eb7d6e297e40f4bafd35a109a7849082124cc1946d6efb31becfbd.json", "requiresBootstrapStackVersion": 6, "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version", "additionalDependencies": [ @@ -34,6 +38,17 @@ "aws-cdk-global-table.assets" ], "metadata": { + "/aws-cdk-global-table": [ + { + "type": "aws:cdk:stack-tags", + "data": [ + { + "Key": "stage", + "Value": "IntegTest" + } + ] + } + ], "/aws-cdk-global-table/Stream/Resource": [ { "type": "aws:cdk:logicalId", @@ -89,7 +104,11 @@ "properties": { "templateFile": "awscdkglobaltableintegDefaultTestDeployAssertA2A9E81F.template.json", "terminationProtection": false, + "tags": { + "stage": "IntegTest" + }, "validateOnSynth": false, + "notificationArns": [], "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-deploy-role-${AWS::AccountId}-${AWS::Region}", "cloudFormationExecutionRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-cfn-exec-role-${AWS::AccountId}-${AWS::Region}", "stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/21fbb51d7b23f6a6c262b46a9caee79d744a3ac019fd45422d988b96d44b2a22.json", @@ -108,6 +127,17 @@ "awscdkglobaltableintegDefaultTestDeployAssertA2A9E81F.assets" ], "metadata": { + "/aws-cdk-global-table-integ/DefaultTest/DeployAssert": [ + { + "type": "aws:cdk:stack-tags", + "data": [ + { + "Key": "stage", + "Value": "IntegTest" + } + ] + } + ], "/aws-cdk-global-table-integ/DefaultTest/DeployAssert/BootstrapVersion": [ { "type": "aws:cdk:logicalId", diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-dynamodb/test/integ.table-v2-global.js.snapshot/tree.json b/packages/@aws-cdk-testing/framework-integ/test/aws-dynamodb/test/integ.table-v2-global.js.snapshot/tree.json index e162d51c8274f..7d72d600d5a9f 100644 --- a/packages/@aws-cdk-testing/framework-integ/test/aws-dynamodb/test/integ.table-v2-global.js.snapshot/tree.json +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-dynamodb/test/integ.table-v2-global.js.snapshot/tree.json @@ -31,7 +31,13 @@ "KeyId": "alias/aws/kinesis" } ] - } + }, + "tags": [ + { + "key": "stage", + "value": "IntegTest" + } + ] } }, "constructInfo": { @@ -187,6 +193,14 @@ } }, "tags": [ + { + "key": "stage", + "value": "IntegTest" + }, + { + "key": "tagAspectKey", + "value": "tagAspectValue" + }, { "key": "USE2ReplicaTagKey", "value": "USE2ReplicaTagValue" @@ -223,6 +237,14 @@ "readCapacityUnits": 10 }, "tags": [ + { + "key": "stage", + "value": "IntegTest" + }, + { + "key": "tagAspectKey", + "value": "tagAspectValue" + }, { "key": "USW2ReplicaTagKey", "value": "USW2ReplicaTagValue" @@ -270,6 +292,14 @@ "readCapacityUnits": 10 }, "tags": [ + { + "key": "stage", + "value": "IntegTest" + }, + { + "key": "tagAspectKey", + "value": "tagAspectValue" + }, { "key": "primaryTableTagKey", "value": "primaryTableTagValue" @@ -347,7 +377,7 @@ "path": "aws-cdk-global-table-integ/DefaultTest/Default", "constructInfo": { "fqn": "constructs.Construct", - "version": "10.3.0" + "version": "10.4.2" } }, "DeployAssert": { @@ -393,7 +423,7 @@ "path": "Tree", "constructInfo": { "fqn": "constructs.Construct", - "version": "10.3.0" + "version": "10.4.2" } } }, diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-dynamodb/test/integ.table-v2-global.ts b/packages/@aws-cdk-testing/framework-integ/test/aws-dynamodb/test/integ.table-v2-global.ts index 8cf849249f998..de8d987c23e91 100644 --- a/packages/@aws-cdk-testing/framework-integ/test/aws-dynamodb/test/integ.table-v2-global.ts +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-dynamodb/test/integ.table-v2-global.ts @@ -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'; @@ -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 }, @@ -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'], diff --git a/packages/aws-cdk-lib/aws-dynamodb/lib/table-v2.ts b/packages/aws-cdk-lib/aws-dynamodb/lib/table-v2.ts index b6507d3f7deb1..ac79fb6fad792 100644 --- a/packages/aws-cdk-lib/aws-dynamodb/lib/table-v2.ts +++ b/packages/aws-cdk-lib/aws-dynamodb/lib/table-v2.ts @@ -4,15 +4,30 @@ import { Capacity } from './capacity'; import { CfnGlobalTable } from './dynamodb.generated'; import { TableEncryptionV2 } from './encryption'; import { + Attribute, + BillingMode, + LocalSecondaryIndexProps, + ProjectionType, + SecondaryIndexProps, StreamViewType, - Attribute, TableClass, LocalSecondaryIndexProps, - SecondaryIndexProps, BillingMode, ProjectionType, + TableClass, } from './shared'; -import { TableBaseV2, ITableV2 } from './table-v2-base'; +import { ITableV2, TableBaseV2 } from './table-v2-base'; import { PolicyDocument } from '../../aws-iam'; import { IStream } from '../../aws-kinesis'; import { IKey, Key } from '../../aws-kms'; -import { ArnFormat, CfnTag, FeatureFlags, Lazy, PhysicalName, RemovalPolicy, Stack, Token } from '../../core'; +import { + ArnFormat, + CfnTag, + FeatureFlags, + Lazy, + PhysicalName, + RemovalPolicy, + Stack, + TagManager, + TagType, + Token, +} from '../../core'; import * as cxapi from '../../cx-api'; const HASH_KEY_TYPE = 'HASH'; @@ -145,7 +160,7 @@ export interface TableOptionsV2 { readonly kinesisStream?: IStream; /** - * Tags to be applied to the table or replica table + * Tags to be applied to the primary table (default replica table). * * @default - no tags */ @@ -483,6 +498,8 @@ export class TableV2 extends TableBaseV2 { protected readonly region: string; + protected readonly tags: TagManager; + private readonly billingMode: string; private readonly partitionKey: Attribute; private readonly hasSortKey: boolean; @@ -516,6 +533,7 @@ export class TableV2 extends TableBaseV2 { this.partitionKey = props.partitionKey; this.hasSortKey = props.sortKey !== undefined; this.region = this.stack.region; + this.tags = new TagManager(TagType.STANDARD, CfnGlobalTable.CFN_RESOURCE_TYPE_NAME); this.encryption = props.encryption; this.encryptionKey = this.encryption?.tableKey; @@ -665,6 +683,7 @@ export class TableV2 extends TableBaseV2 { private configureReplicaTable(props: ReplicaTableProps): CfnGlobalTable.ReplicaSpecificationProperty { const pointInTimeRecovery = props.pointInTimeRecovery ?? this.tableOptions.pointInTimeRecovery; const contributorInsights = props.contributorInsights ?? this.tableOptions.contributorInsights; + /* * Feature flag set as the following may be a breaking change. * @see https://github.com/aws/aws-cdk/pull/31097 @@ -674,6 +693,15 @@ export class TableV2 extends TableBaseV2 { ? (props.region === this.region ? this.tableOptions.resourcePolicy : props.resourcePolicy) || undefined : props.resourcePolicy ?? this.tableOptions.resourcePolicy; + const propTags: Record = (props.tags ?? []).reduce((p, item) => + ({ ...p, [item.key]: item.value }), {}, + ); + + const tags: CfnTag[] = Object.entries({ + ...this.tags.tagValues(), + ...propTags, + }).map(([k, v]) => ({ key: k, value: v })); + return { region: props.region, globalSecondaryIndexes: this.configureReplicaGlobalSecondaryIndexes(props.globalSecondaryIndexOptions), @@ -692,7 +720,7 @@ export class TableV2 extends TableBaseV2 { readProvisionedThroughputSettings: props.readCapacity ? props.readCapacity._renderReadCapacity() : this.readProvisioning, - tags: props.tags, + tags: tags.length === 0 ? undefined : tags, readOnDemandThroughputSettings: props.maxReadRequestUnits ? { maxReadRequestUnits: props.maxReadRequestUnits } : this.maxReadRequestUnits diff --git a/packages/aws-cdk-lib/aws-dynamodb/test/table-v2.test.ts b/packages/aws-cdk-lib/aws-dynamodb/test/table-v2.test.ts index 63bbf3319b73e..a4c9c66808ff2 100644 --- a/packages/aws-cdk-lib/aws-dynamodb/test/table-v2.test.ts +++ b/packages/aws-cdk-lib/aws-dynamodb/test/table-v2.test.ts @@ -2,7 +2,7 @@ import { Match, Template } from '../../assertions'; import { ArnPrincipal, PolicyDocument, PolicyStatement } from '../../aws-iam'; import { Stream } from '../../aws-kinesis'; import { Key } from '../../aws-kms'; -import { CfnDeletionPolicy, Lazy, RemovalPolicy, Stack } from '../../core'; +import { CfnDeletionPolicy, Lazy, RemovalPolicy, Stack, Tags } from '../../core'; import { AttributeType, Billing, Capacity, GlobalSecondaryIndexPropsV2, TableV2, LocalSecondaryIndexProps, ProjectionType, StreamViewType, TableClass, TableEncryptionV2, @@ -1293,6 +1293,107 @@ describe('replica tables', () => { }); }); + test('with TagAspect', () => { + // GIVEN + const stack = new Stack(undefined, 'Stack', { env: { region: 'us-east-1' } }); + + // WHEN + const table = new TableV2(stack, 'Table', { + partitionKey: { name: 'pk', type: AttributeType.STRING }, + replicas: [{ + region: 'us-west-1', + }], + }); + + Tags.of(table).add('tagKey', 'tagValue'); + + // THEN + Template.fromStack(stack).hasResourceProperties('AWS::DynamoDB::GlobalTable', { + Replicas: [ + { + Region: 'us-west-1', + Tags: [{ Key: 'tagKey', Value: 'tagValue' }], + }, + { + Region: 'us-east-1', + Tags: [{ Key: 'tagKey', Value: 'tagValue' }], + }, + ], + }); + }); + + test('with TagAspect on parent scope', () => { + // GIVEN + const stack = new Stack(undefined, 'Stack', { env: { region: 'us-east-1' } }); + + // WHEN + new TableV2(stack, 'Table', { + partitionKey: { name: 'pk', type: AttributeType.STRING }, + replicas: [{ + region: 'us-west-1', + }], + }); + + Tags.of(stack).add('stage', 'Prod'); + + // THEN + Template.fromStack(stack).hasResourceProperties('AWS::DynamoDB::GlobalTable', { + Replicas: [ + { + Region: 'us-west-1', + Tags: [{ Key: 'stage', Value: 'Prod' }], + }, + { + Region: 'us-east-1', + Tags: [{ Key: 'stage', Value: 'Prod' }], + }, + ], + }); + }); + + test('replica tags override tag aspect tags', () => { + // GIVEN + const stack = new Stack(undefined, 'Stack', { env: { region: 'us-east-1' } }); + + // WHEN + const table = new TableV2(stack, 'Table', { + partitionKey: { name: 'pk', type: AttributeType.STRING }, + replicas: [{ + region: 'us-west-1', + tags: [{ key: 'tableTagProperty', value: 'replicaW1TagPropertyValue' }], + }, { + region: 'us-west-2', + }], + tags: [{ key: 'tableTagProperty', value: 'defaultReplicaTagPropertyValue' }], + }); + + Tags.of(table).add('tableTagProperty', 'tagAspectValue'); + + // THEN + Template.fromStack(stack).hasResourceProperties('AWS::DynamoDB::GlobalTable', { + Replicas: [ + { + Region: 'us-west-1', + Tags: [ + { Key: 'tableTagProperty', Value: 'replicaW1TagPropertyValue' }, + ], + }, + { + Region: 'us-west-2', + Tags: [ + { Key: 'tableTagProperty', Value: 'tagAspectValue' }, + ], + }, + { + Region: 'us-east-1', + Tags: [ + { Key: 'tableTagProperty', Value: 'defaultReplicaTagPropertyValue' }, + ], + }, + ], + }); + }); + test('with per-replica kinesis stream', () => { // GIVEN const stack = new Stack(undefined, 'Stack', { env: { region: 'us-west-2' } }); @@ -3007,4 +3108,4 @@ test('Resource policy test', () => { }, ], }); -}); \ No newline at end of file +});