Skip to content

Commit

Permalink
feat(aws-dynamodb): Support DynamoDB PITR (#701)
Browse files Browse the repository at this point in the history
This patch supports DynamoDB PITR.
  • Loading branch information
jungseoklee authored and Elad Ben-Israel committed Sep 13, 2018
1 parent 57b92be commit 7a4d7b7
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 0 deletions.
7 changes: 7 additions & 0 deletions packages/@aws-cdk/aws-dynamodb/lib/table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ export interface TableProps {
*/
tableName?: string;

/**
* Whether point-in-time recovery is enabled.
* @default undefined, point-in-time recovery is disabled
*/
pitrEnabled?: boolean;

/**
* Whether server-side encryption is enabled.
* @default undefined, server-side encryption is disabled
Expand Down Expand Up @@ -122,6 +128,7 @@ export class Table extends Construct {
tableName: props.tableName,
keySchema: this.keySchema,
attributeDefinitions: this.attributeDefinitions,
pointInTimeRecoverySpecification: props.pitrEnabled ? { pointInTimeRecoveryEnabled: props.pitrEnabled } : undefined,
provisionedThroughput: { readCapacityUnits, writeCapacityUnits },
sseSpecification: props.sseEnabled ? { sseEnabled: props.sseEnabled } : undefined,
streamSpecification: props.streamSpecification ? { streamViewType: props.streamSpecification } : undefined,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
"AttributeType": "N"
}
],
"PointInTimeRecoverySpecification": {
"PointInTimeRecoveryEnabled": true
},
"SSESpecification": {
"SSEEnabled": true
},
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 @@ -6,6 +6,7 @@ const app = new App(process.argv);
const stack = new Stack(app, 'aws-cdk-dynamodb');

const table = new Table(stack, 'Table', {
pitrEnabled: true,
sseEnabled: true,
streamSpecification: StreamViewType.KeysOnly,
ttlAttributeName: 'timeToLive'
Expand Down
30 changes: 30 additions & 0 deletions packages/@aws-cdk/aws-dynamodb/test/test.dynamodb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,34 @@ export = {

test.done();
},
'point-in-time recovery is not enabled'(test: Test) {
const app = new TestApp();
new Table(app.stack, 'MyTable')
.addPartitionKey('partitionKey', KeyAttributeType.Binary)
.addSortKey('sortKey', KeyAttributeType.Number);
const template = app.synthesizeTemplate();

test.deepEqual(template, {
Resources: {
MyTable794EDED1: {
Type: 'AWS::DynamoDB::Table',
Properties: {
AttributeDefinitions: [
{ AttributeName: 'partitionKey', AttributeType: 'B' },
{ AttributeName: 'sortKey', AttributeType: 'N' }
],
KeySchema: [
{ AttributeName: 'partitionKey', KeyType: 'HASH' },
{ AttributeName: 'sortKey', KeyType: 'RANGE' }
],
ProvisionedThroughput: { ReadCapacityUnits: 5, WriteCapacityUnits: 5 },
}
}
}
});

test.done();
},
'server-side encryption is not enabled'(test: Test) {
const app = new TestApp();
new Table(app.stack, 'MyTable')
Expand Down Expand Up @@ -257,6 +285,7 @@ export = {
tableName: 'MyTable',
readCapacity: 42,
writeCapacity: 1337,
pitrEnabled: true,
sseEnabled: true,
streamSpecification: StreamViewType.KeysOnly,
ttlAttributeName: 'timeToLive'
Expand All @@ -282,6 +311,7 @@ export = {
ReadCapacityUnits: 42,
WriteCapacityUnits: 1337
},
PointInTimeRecoverySpecification: { PointInTimeRecoveryEnabled: true },
SSESpecification: { SSEEnabled: true },
StreamSpecification: { StreamViewType: 'KEYS_ONLY' },
TableName: 'MyTable',
Expand Down

0 comments on commit 7a4d7b7

Please sign in to comment.