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

fix(dynamoDB): make TableV2 taggable #31867

Merged
merged 9 commits into from
Nov 2, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

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 @@ -124,7 +124,13 @@
"MaxReadRequestUnits": 222
},
"Region": "eu-west-1",
"TableClass": "STANDARD_INFREQUENT_ACCESS"
"TableClass": "STANDARD_INFREQUENT_ACCESS",
"Tags": [
{
"Key": "primaryTableTagKey",
"Value": "primaryTableTagValue"
}
]
GavinZZ marked this conversation as resolved.
Show resolved Hide resolved
},
{
"ContributorInsightsSpecification": {
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.

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 @@ -148,6 +148,10 @@
"Region": "us-east-2",
"TableClass": "STANDARD_INFREQUENT_ACCESS",
"Tags": [
{
"Key": "primaryTableTagKey",
"Value": "USE2Replica"
},
{
"Key": "USE2ReplicaTagKey",
"Value": "USE2ReplicaTagValue"
Expand Down Expand Up @@ -184,6 +188,10 @@
"Region": "us-west-2",
"TableClass": "STANDARD",
"Tags": [
{
"Key": "primaryTableTagKey",
"Value": "primaryTableTagValue"
},
{
"Key": "USW2ReplicaTagKey",
"Value": "USW2ReplicaTagValue"
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
Expand Up @@ -52,7 +52,13 @@ class TestStack extends Stack {
contributorInsights: false,
},
},
tags: [{ key: 'USE2ReplicaTagKey', value: 'USE2ReplicaTagValue' }],
tags: [{
key: 'USE2ReplicaTagKey',
value: 'USE2ReplicaTagValue',
}, {
key: 'primaryTableTagKey',
value: 'USE2Replica',
}],
},
{
region: 'us-west-2',
Expand Down
38 changes: 33 additions & 5 deletions packages/aws-cdk-lib/aws-dynamodb/lib/table-v2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -483,6 +498,8 @@ export class TableV2 extends TableBaseV2 {

protected readonly region: string;

protected readonly tags: TagManager;
moelasmar marked this conversation as resolved.
Show resolved Hide resolved

private readonly billingMode: string;
private readonly partitionKey: Attribute;
private readonly hasSortKey: boolean;
Expand Down Expand Up @@ -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, props.tags);
GavinZZ marked this conversation as resolved.
Show resolved Hide resolved

this.encryption = props.encryption;
this.encryptionKey = this.encryption?.tableKey;
Expand Down Expand Up @@ -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
Expand All @@ -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<string, string> = (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 }));

moelasmar marked this conversation as resolved.
Show resolved Hide resolved
return {
region: props.region,
globalSecondaryIndexes: this.configureReplicaGlobalSecondaryIndexes(props.globalSecondaryIndexOptions),
Expand All @@ -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
Expand Down
Loading
Loading