Skip to content

Commit

Permalink
feat(aws-dynamodb): tags support (#814)
Browse files Browse the repository at this point in the history
Adds support for tags for DynamoDB table
  • Loading branch information
jungseoklee authored and Elad Ben-Israel committed Oct 8, 2018
1 parent eb4bacf commit 644947a
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 19 deletions.
9 changes: 8 additions & 1 deletion packages/@aws-cdk/aws-dynamodb/lib/table.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { cloudformation as applicationautoscaling } from '@aws-cdk/aws-applicationautoscaling';
import { Role } from '@aws-cdk/aws-iam';
import { Construct, PolicyStatement, PolicyStatementEffect, ServicePrincipal } from '@aws-cdk/cdk';
import { Construct, PolicyStatement, PolicyStatementEffect, ServicePrincipal, TagManager, Tags } from '@aws-cdk/cdk';
import { cloudformation as dynamodb } from './dynamodb.generated';

const HASH_KEY_TYPE = 'HASH';
Expand Down Expand Up @@ -57,6 +57,12 @@ export interface TableProps {
*/
streamSpecification?: StreamViewType;

/**
* The AWS resource tags to associate with the table.
* @default undefined
*/
tags?: Tags;

/**
* The name of TTL attribute.
* @default undefined, TTL is disabled
Expand Down Expand Up @@ -202,6 +208,7 @@ export class Table extends Construct {
provisionedThroughput: { readCapacityUnits: props.readCapacity || 5, writeCapacityUnits: props.writeCapacity || 5 },
sseSpecification: props.sseEnabled ? { sseEnabled: props.sseEnabled } : undefined,
streamSpecification: props.streamSpecification ? { streamViewType: props.streamSpecification } : undefined,
tags: new TagManager(this, { initialTags: props.tags }),
timeToLiveSpecification: props.ttlAttributeName ? { attributeName: props.ttlAttributeName, enabled: true } : undefined
});

Expand Down
15 changes: 12 additions & 3 deletions packages/@aws-cdk/aws-dynamodb/test/integ.dynamodb.expected.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
}
],
"GlobalSecondaryIndexes": [],
"LocalSecondaryIndexes": []
"LocalSecondaryIndexes": [],
"Tags": []
}
},
"TableWithGlobalAndLocalSecondaryIndexBC540710": {
Expand Down Expand Up @@ -259,6 +260,12 @@
"StreamSpecification": {
"StreamViewType": "KEYS_ONLY"
},
"Tags": [
{
"Key": "Environment",
"Value": "Production"
}
],
"TimeToLiveSpecification": {
"AttributeName": "timeToLive",
"Enabled": true
Expand Down Expand Up @@ -306,7 +313,8 @@
}
}
],
"LocalSecondaryIndexes": []
"LocalSecondaryIndexes": [],
"Tags": []
}
},
"TableWithLocalSecondaryIndex4DA3D08F": {
Expand Down Expand Up @@ -358,7 +366,8 @@
"ProjectionType": "ALL"
}
}
]
],
"Tags": []
}
}
}
Expand Down
1 change: 1 addition & 0 deletions packages/@aws-cdk/aws-dynamodb/test/integ.dynamodb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ const tableWithGlobalAndLocalSecondaryIndex = new Table(stack, TABLE_WITH_GLOBAL
pitrEnabled: true,
sseEnabled: true,
streamSpecification: StreamViewType.KeysOnly,
tags: { Environment: 'Production' },
ttlAttributeName: 'timeToLive'
});

Expand Down
58 changes: 43 additions & 15 deletions packages/@aws-cdk/aws-dynamodb/test/test.dynamodb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ export = {
KeySchema: [{ AttributeName: 'hashKey', KeyType: 'HASH' }],
ProvisionedThroughput: { ReadCapacityUnits: 5, WriteCapacityUnits: 5 },
GlobalSecondaryIndexes: [],
LocalSecondaryIndexes: []
LocalSecondaryIndexes: [],
Tags: []
}
}
}
Expand Down Expand Up @@ -114,7 +115,8 @@ export = {
],
ProvisionedThroughput: { ReadCapacityUnits: 5, WriteCapacityUnits: 5 },
GlobalSecondaryIndexes: [],
LocalSecondaryIndexes: []
LocalSecondaryIndexes: [],
Tags: []
}
}
}
Expand Down Expand Up @@ -145,7 +147,8 @@ export = {
],
ProvisionedThroughput: { ReadCapacityUnits: 5, WriteCapacityUnits: 5 },
GlobalSecondaryIndexes: [],
LocalSecondaryIndexes: []
LocalSecondaryIndexes: [],
Tags: []
}
}
}
Expand Down Expand Up @@ -176,7 +179,8 @@ export = {
],
ProvisionedThroughput: { ReadCapacityUnits: 5, WriteCapacityUnits: 5 },
GlobalSecondaryIndexes: [],
LocalSecondaryIndexes: []
LocalSecondaryIndexes: [],
Tags: []
}
}
}
Expand Down Expand Up @@ -207,7 +211,8 @@ export = {
],
ProvisionedThroughput: { ReadCapacityUnits: 5, WriteCapacityUnits: 5 },
GlobalSecondaryIndexes: [],
LocalSecondaryIndexes: []
LocalSecondaryIndexes: [],
Tags: []
}
}
}
Expand Down Expand Up @@ -238,7 +243,8 @@ export = {
],
ProvisionedThroughput: { ReadCapacityUnits: 5, WriteCapacityUnits: 5 },
GlobalSecondaryIndexes: [],
LocalSecondaryIndexes: []
LocalSecondaryIndexes: [],
Tags: []
}
}
}
Expand Down Expand Up @@ -276,7 +282,8 @@ export = {
ProvisionedThroughput: { ReadCapacityUnits: 42, WriteCapacityUnits: 1337 },
GlobalSecondaryIndexes: [],
LocalSecondaryIndexes: [],
TableName: 'MyTable'
TableName: 'MyTable',
Tags: []
}
}
}
Expand Down Expand Up @@ -314,7 +321,8 @@ export = {
{ AttributeName: 'sortKey', AttributeType: 'N' }
],
StreamSpecification: { StreamViewType: 'NEW_IMAGE' },
TableName: 'MyTable'
TableName: 'MyTable',
Tags: []
}
}
}
Expand Down Expand Up @@ -352,7 +360,8 @@ export = {
{ AttributeName: 'sortKey', AttributeType: 'N' }
],
StreamSpecification: { StreamViewType: 'OLD_IMAGE' },
TableName: 'MyTable'
TableName: 'MyTable',
Tags: []
}
}
}
Expand All @@ -371,6 +380,7 @@ export = {
pitrEnabled: true,
sseEnabled: true,
streamSpecification: StreamViewType.KeysOnly,
tags: { Environment: 'Production' },
ttlAttributeName: 'timeToLive'
});
table.addPartitionKey(TABLE_PARTITION_KEY);
Expand Down Expand Up @@ -400,6 +410,7 @@ export = {
SSESpecification: { SSEEnabled: true },
StreamSpecification: { StreamViewType: 'KEYS_ONLY' },
TableName: 'MyTable',
Tags: [ { Key: 'Environment', Value: 'Production' } ],
TimeToLiveSpecification: { AttributeName: 'timeToLive', Enabled: true }
}
}
Expand Down Expand Up @@ -448,6 +459,7 @@ export = {
}
],
LocalSecondaryIndexes: [],
Tags: []
}
}
}
Expand Down Expand Up @@ -499,6 +511,7 @@ export = {
}
],
LocalSecondaryIndexes: [],
Tags: []
}
}
}
Expand Down Expand Up @@ -548,6 +561,7 @@ export = {
}
],
LocalSecondaryIndexes: [],
Tags: []
}
}
}
Expand Down Expand Up @@ -601,6 +615,7 @@ export = {
}
],
LocalSecondaryIndexes: [],
Tags: []
}
}
}
Expand Down Expand Up @@ -771,6 +786,7 @@ export = {
},
],
LocalSecondaryIndexes: [],
Tags: []
}
}
}
Expand Down Expand Up @@ -832,6 +848,7 @@ export = {
}
],
LocalSecondaryIndexes: [],
Tags: []
}
}
}
Expand Down Expand Up @@ -877,6 +894,7 @@ export = {
Projection: { ProjectionType: 'ALL' },
}
],
Tags: []
}
}
}
Expand Down Expand Up @@ -923,6 +941,7 @@ export = {
Projection: { ProjectionType: 'KEYS_ONLY' },
}
],
Tags: []
}
}
}
Expand Down Expand Up @@ -972,6 +991,7 @@ export = {
Projection: { NonKeyAttributes: ['lsiNonKey0', 'lsiNonKey1'], ProjectionType: 'INCLUDE' },
}
],
Tags: []
}
}
}
Expand Down Expand Up @@ -1076,7 +1096,8 @@ export = {
AttributeDefinitions:
[ { AttributeName: 'hashKey', AttributeType: 'S' },
{ AttributeName: 'sortKey', AttributeType: 'N' } ],
TableName: 'MyTable' } },
TableName: 'MyTable',
Tags: [] } },
MyTableReadAutoScalingRoleFEE68E49:
{ Type: 'AWS::IAM::Role',
Properties:
Expand Down Expand Up @@ -1158,7 +1179,8 @@ export = {
AttributeDefinitions:
[ { AttributeName: 'hashKey', AttributeType: 'S' },
{ AttributeName: 'sortKey', AttributeType: 'N' } ],
TableName: 'MyTable' } },
TableName: 'MyTable',
Tags: [] } },
MyTableReadAutoScalingRoleFEE68E49:
{ Type: 'AWS::IAM::Role',
Properties:
Expand Down Expand Up @@ -1268,7 +1290,8 @@ export = {
AttributeDefinitions:
[ { AttributeName: 'hashKey', AttributeType: 'S' },
{ AttributeName: 'sortKey', AttributeType: 'N' } ],
TableName: 'MyTable' } },
TableName: 'MyTable',
Tags: [] } },
MyTableReadAutoScalingRoleFEE68E49:
{ Type: 'AWS::IAM::Role',
Properties:
Expand Down Expand Up @@ -1346,6 +1369,7 @@ export = {
ProvisionedThroughput: { ReadCapacityUnits: 42, WriteCapacityUnits: 1337 },
GlobalSecondaryIndexes: [],
LocalSecondaryIndexes: [],
Tags: [],
AttributeDefinitions:
[ { AttributeName: 'hashKey', AttributeType: 'S' },
{ AttributeName: 'sortKey', AttributeType: 'N' } ] } },
Expand Down Expand Up @@ -1553,7 +1577,8 @@ export = {
AttributeDefinitions:
[ { AttributeName: 'hashKey', AttributeType: 'S' },
{ AttributeName: 'sortKey', AttributeType: 'N' } ],
TableName: 'MyTable' } },
TableName: 'MyTable',
Tags: [] } },
MyTableWriteAutoScalingRoleDF7775DE:
{ Type: 'AWS::IAM::Role',
Properties:
Expand Down Expand Up @@ -1635,7 +1660,8 @@ export = {
AttributeDefinitions:
[ { AttributeName: 'hashKey', AttributeType: 'S' },
{ AttributeName: 'sortKey', AttributeType: 'N' } ],
TableName: 'MyTable' } },
TableName: 'MyTable',
Tags: [] } },
MyTableWriteAutoScalingRoleDF7775DE:
{ Type: 'AWS::IAM::Role',
Properties:
Expand Down Expand Up @@ -1745,7 +1771,8 @@ export = {
AttributeDefinitions:
[ { AttributeName: 'hashKey', AttributeType: 'S' },
{ AttributeName: 'sortKey', AttributeType: 'N' } ],
TableName: 'MyTable' } },
TableName: 'MyTable',
Tags: [] } },
MyTableWriteAutoScalingRoleDF7775DE:
{ Type: 'AWS::IAM::Role',
Properties:
Expand Down Expand Up @@ -1823,6 +1850,7 @@ export = {
ProvisionedThroughput: { ReadCapacityUnits: 42, WriteCapacityUnits: 1337 },
GlobalSecondaryIndexes: [],
LocalSecondaryIndexes: [],
Tags: [],
AttributeDefinitions:
[ { AttributeName: 'hashKey', AttributeType: 'S' },
{ AttributeName: 'sortKey', AttributeType: 'N' } ] } },
Expand Down

0 comments on commit 644947a

Please sign in to comment.