Skip to content

Commit 644947a

Browse files
jungseokleeElad Ben-Israel
authored and
Elad Ben-Israel
committed
feat(aws-dynamodb): tags support (#814)
Adds support for tags for DynamoDB table
1 parent eb4bacf commit 644947a

File tree

4 files changed

+64
-19
lines changed

4 files changed

+64
-19
lines changed

Diff for: packages/@aws-cdk/aws-dynamodb/lib/table.ts

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { cloudformation as applicationautoscaling } from '@aws-cdk/aws-applicationautoscaling';
22
import { Role } from '@aws-cdk/aws-iam';
3-
import { Construct, PolicyStatement, PolicyStatementEffect, ServicePrincipal } from '@aws-cdk/cdk';
3+
import { Construct, PolicyStatement, PolicyStatementEffect, ServicePrincipal, TagManager, Tags } from '@aws-cdk/cdk';
44
import { cloudformation as dynamodb } from './dynamodb.generated';
55

66
const HASH_KEY_TYPE = 'HASH';
@@ -57,6 +57,12 @@ export interface TableProps {
5757
*/
5858
streamSpecification?: StreamViewType;
5959

60+
/**
61+
* The AWS resource tags to associate with the table.
62+
* @default undefined
63+
*/
64+
tags?: Tags;
65+
6066
/**
6167
* The name of TTL attribute.
6268
* @default undefined, TTL is disabled
@@ -202,6 +208,7 @@ export class Table extends Construct {
202208
provisionedThroughput: { readCapacityUnits: props.readCapacity || 5, writeCapacityUnits: props.writeCapacity || 5 },
203209
sseSpecification: props.sseEnabled ? { sseEnabled: props.sseEnabled } : undefined,
204210
streamSpecification: props.streamSpecification ? { streamViewType: props.streamSpecification } : undefined,
211+
tags: new TagManager(this, { initialTags: props.tags }),
205212
timeToLiveSpecification: props.ttlAttributeName ? { attributeName: props.ttlAttributeName, enabled: true } : undefined
206213
});
207214

Diff for: packages/@aws-cdk/aws-dynamodb/test/integ.dynamodb.expected.json

+12-3
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020
}
2121
],
2222
"GlobalSecondaryIndexes": [],
23-
"LocalSecondaryIndexes": []
23+
"LocalSecondaryIndexes": [],
24+
"Tags": []
2425
}
2526
},
2627
"TableWithGlobalAndLocalSecondaryIndexBC540710": {
@@ -259,6 +260,12 @@
259260
"StreamSpecification": {
260261
"StreamViewType": "KEYS_ONLY"
261262
},
263+
"Tags": [
264+
{
265+
"Key": "Environment",
266+
"Value": "Production"
267+
}
268+
],
262269
"TimeToLiveSpecification": {
263270
"AttributeName": "timeToLive",
264271
"Enabled": true
@@ -306,7 +313,8 @@
306313
}
307314
}
308315
],
309-
"LocalSecondaryIndexes": []
316+
"LocalSecondaryIndexes": [],
317+
"Tags": []
310318
}
311319
},
312320
"TableWithLocalSecondaryIndex4DA3D08F": {
@@ -358,7 +366,8 @@
358366
"ProjectionType": "ALL"
359367
}
360368
}
361-
]
369+
],
370+
"Tags": []
362371
}
363372
}
364373
}

Diff for: packages/@aws-cdk/aws-dynamodb/test/integ.dynamodb.ts

+1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ const tableWithGlobalAndLocalSecondaryIndex = new Table(stack, TABLE_WITH_GLOBAL
4747
pitrEnabled: true,
4848
sseEnabled: true,
4949
streamSpecification: StreamViewType.KeysOnly,
50+
tags: { Environment: 'Production' },
5051
ttlAttributeName: 'timeToLive'
5152
});
5253

Diff for: packages/@aws-cdk/aws-dynamodb/test/test.dynamodb.ts

+43-15
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,8 @@ export = {
8383
KeySchema: [{ AttributeName: 'hashKey', KeyType: 'HASH' }],
8484
ProvisionedThroughput: { ReadCapacityUnits: 5, WriteCapacityUnits: 5 },
8585
GlobalSecondaryIndexes: [],
86-
LocalSecondaryIndexes: []
86+
LocalSecondaryIndexes: [],
87+
Tags: []
8788
}
8889
}
8990
}
@@ -114,7 +115,8 @@ export = {
114115
],
115116
ProvisionedThroughput: { ReadCapacityUnits: 5, WriteCapacityUnits: 5 },
116117
GlobalSecondaryIndexes: [],
117-
LocalSecondaryIndexes: []
118+
LocalSecondaryIndexes: [],
119+
Tags: []
118120
}
119121
}
120122
}
@@ -145,7 +147,8 @@ export = {
145147
],
146148
ProvisionedThroughput: { ReadCapacityUnits: 5, WriteCapacityUnits: 5 },
147149
GlobalSecondaryIndexes: [],
148-
LocalSecondaryIndexes: []
150+
LocalSecondaryIndexes: [],
151+
Tags: []
149152
}
150153
}
151154
}
@@ -176,7 +179,8 @@ export = {
176179
],
177180
ProvisionedThroughput: { ReadCapacityUnits: 5, WriteCapacityUnits: 5 },
178181
GlobalSecondaryIndexes: [],
179-
LocalSecondaryIndexes: []
182+
LocalSecondaryIndexes: [],
183+
Tags: []
180184
}
181185
}
182186
}
@@ -207,7 +211,8 @@ export = {
207211
],
208212
ProvisionedThroughput: { ReadCapacityUnits: 5, WriteCapacityUnits: 5 },
209213
GlobalSecondaryIndexes: [],
210-
LocalSecondaryIndexes: []
214+
LocalSecondaryIndexes: [],
215+
Tags: []
211216
}
212217
}
213218
}
@@ -238,7 +243,8 @@ export = {
238243
],
239244
ProvisionedThroughput: { ReadCapacityUnits: 5, WriteCapacityUnits: 5 },
240245
GlobalSecondaryIndexes: [],
241-
LocalSecondaryIndexes: []
246+
LocalSecondaryIndexes: [],
247+
Tags: []
242248
}
243249
}
244250
}
@@ -276,7 +282,8 @@ export = {
276282
ProvisionedThroughput: { ReadCapacityUnits: 42, WriteCapacityUnits: 1337 },
277283
GlobalSecondaryIndexes: [],
278284
LocalSecondaryIndexes: [],
279-
TableName: 'MyTable'
285+
TableName: 'MyTable',
286+
Tags: []
280287
}
281288
}
282289
}
@@ -314,7 +321,8 @@ export = {
314321
{ AttributeName: 'sortKey', AttributeType: 'N' }
315322
],
316323
StreamSpecification: { StreamViewType: 'NEW_IMAGE' },
317-
TableName: 'MyTable'
324+
TableName: 'MyTable',
325+
Tags: []
318326
}
319327
}
320328
}
@@ -352,7 +360,8 @@ export = {
352360
{ AttributeName: 'sortKey', AttributeType: 'N' }
353361
],
354362
StreamSpecification: { StreamViewType: 'OLD_IMAGE' },
355-
TableName: 'MyTable'
363+
TableName: 'MyTable',
364+
Tags: []
356365
}
357366
}
358367
}
@@ -371,6 +380,7 @@ export = {
371380
pitrEnabled: true,
372381
sseEnabled: true,
373382
streamSpecification: StreamViewType.KeysOnly,
383+
tags: { Environment: 'Production' },
374384
ttlAttributeName: 'timeToLive'
375385
});
376386
table.addPartitionKey(TABLE_PARTITION_KEY);
@@ -400,6 +410,7 @@ export = {
400410
SSESpecification: { SSEEnabled: true },
401411
StreamSpecification: { StreamViewType: 'KEYS_ONLY' },
402412
TableName: 'MyTable',
413+
Tags: [ { Key: 'Environment', Value: 'Production' } ],
403414
TimeToLiveSpecification: { AttributeName: 'timeToLive', Enabled: true }
404415
}
405416
}
@@ -448,6 +459,7 @@ export = {
448459
}
449460
],
450461
LocalSecondaryIndexes: [],
462+
Tags: []
451463
}
452464
}
453465
}
@@ -499,6 +511,7 @@ export = {
499511
}
500512
],
501513
LocalSecondaryIndexes: [],
514+
Tags: []
502515
}
503516
}
504517
}
@@ -548,6 +561,7 @@ export = {
548561
}
549562
],
550563
LocalSecondaryIndexes: [],
564+
Tags: []
551565
}
552566
}
553567
}
@@ -601,6 +615,7 @@ export = {
601615
}
602616
],
603617
LocalSecondaryIndexes: [],
618+
Tags: []
604619
}
605620
}
606621
}
@@ -771,6 +786,7 @@ export = {
771786
},
772787
],
773788
LocalSecondaryIndexes: [],
789+
Tags: []
774790
}
775791
}
776792
}
@@ -832,6 +848,7 @@ export = {
832848
}
833849
],
834850
LocalSecondaryIndexes: [],
851+
Tags: []
835852
}
836853
}
837854
}
@@ -877,6 +894,7 @@ export = {
877894
Projection: { ProjectionType: 'ALL' },
878895
}
879896
],
897+
Tags: []
880898
}
881899
}
882900
}
@@ -923,6 +941,7 @@ export = {
923941
Projection: { ProjectionType: 'KEYS_ONLY' },
924942
}
925943
],
944+
Tags: []
926945
}
927946
}
928947
}
@@ -972,6 +991,7 @@ export = {
972991
Projection: { NonKeyAttributes: ['lsiNonKey0', 'lsiNonKey1'], ProjectionType: 'INCLUDE' },
973992
}
974993
],
994+
Tags: []
975995
}
976996
}
977997
}
@@ -1076,7 +1096,8 @@ export = {
10761096
AttributeDefinitions:
10771097
[ { AttributeName: 'hashKey', AttributeType: 'S' },
10781098
{ AttributeName: 'sortKey', AttributeType: 'N' } ],
1079-
TableName: 'MyTable' } },
1099+
TableName: 'MyTable',
1100+
Tags: [] } },
10801101
MyTableReadAutoScalingRoleFEE68E49:
10811102
{ Type: 'AWS::IAM::Role',
10821103
Properties:
@@ -1158,7 +1179,8 @@ export = {
11581179
AttributeDefinitions:
11591180
[ { AttributeName: 'hashKey', AttributeType: 'S' },
11601181
{ AttributeName: 'sortKey', AttributeType: 'N' } ],
1161-
TableName: 'MyTable' } },
1182+
TableName: 'MyTable',
1183+
Tags: [] } },
11621184
MyTableReadAutoScalingRoleFEE68E49:
11631185
{ Type: 'AWS::IAM::Role',
11641186
Properties:
@@ -1268,7 +1290,8 @@ export = {
12681290
AttributeDefinitions:
12691291
[ { AttributeName: 'hashKey', AttributeType: 'S' },
12701292
{ AttributeName: 'sortKey', AttributeType: 'N' } ],
1271-
TableName: 'MyTable' } },
1293+
TableName: 'MyTable',
1294+
Tags: [] } },
12721295
MyTableReadAutoScalingRoleFEE68E49:
12731296
{ Type: 'AWS::IAM::Role',
12741297
Properties:
@@ -1346,6 +1369,7 @@ export = {
13461369
ProvisionedThroughput: { ReadCapacityUnits: 42, WriteCapacityUnits: 1337 },
13471370
GlobalSecondaryIndexes: [],
13481371
LocalSecondaryIndexes: [],
1372+
Tags: [],
13491373
AttributeDefinitions:
13501374
[ { AttributeName: 'hashKey', AttributeType: 'S' },
13511375
{ AttributeName: 'sortKey', AttributeType: 'N' } ] } },
@@ -1553,7 +1577,8 @@ export = {
15531577
AttributeDefinitions:
15541578
[ { AttributeName: 'hashKey', AttributeType: 'S' },
15551579
{ AttributeName: 'sortKey', AttributeType: 'N' } ],
1556-
TableName: 'MyTable' } },
1580+
TableName: 'MyTable',
1581+
Tags: [] } },
15571582
MyTableWriteAutoScalingRoleDF7775DE:
15581583
{ Type: 'AWS::IAM::Role',
15591584
Properties:
@@ -1635,7 +1660,8 @@ export = {
16351660
AttributeDefinitions:
16361661
[ { AttributeName: 'hashKey', AttributeType: 'S' },
16371662
{ AttributeName: 'sortKey', AttributeType: 'N' } ],
1638-
TableName: 'MyTable' } },
1663+
TableName: 'MyTable',
1664+
Tags: [] } },
16391665
MyTableWriteAutoScalingRoleDF7775DE:
16401666
{ Type: 'AWS::IAM::Role',
16411667
Properties:
@@ -1745,7 +1771,8 @@ export = {
17451771
AttributeDefinitions:
17461772
[ { AttributeName: 'hashKey', AttributeType: 'S' },
17471773
{ AttributeName: 'sortKey', AttributeType: 'N' } ],
1748-
TableName: 'MyTable' } },
1774+
TableName: 'MyTable',
1775+
Tags: [] } },
17491776
MyTableWriteAutoScalingRoleDF7775DE:
17501777
{ Type: 'AWS::IAM::Role',
17511778
Properties:
@@ -1823,6 +1850,7 @@ export = {
18231850
ProvisionedThroughput: { ReadCapacityUnits: 42, WriteCapacityUnits: 1337 },
18241851
GlobalSecondaryIndexes: [],
18251852
LocalSecondaryIndexes: [],
1853+
Tags: [],
18261854
AttributeDefinitions:
18271855
[ { AttributeName: 'hashKey', AttributeType: 'S' },
18281856
{ AttributeName: 'sortKey', AttributeType: 'N' } ] } },

0 commit comments

Comments
 (0)