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

Added DynamoDB Table Stream #633

Merged
merged 3 commits into from
Aug 28, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
29 changes: 23 additions & 6 deletions packages/@aws-cdk/aws-dynamodb/lib/table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,11 @@ export interface TableProps {
tableName?: string;

/**
* The Type of Stream to create.
* @default ''
* When an item in the table is modified, StreamViewType determines what information
* is written to the stream for this table. Valid values for StreamViewType are:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

broken sentence

* @default undefined
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Describe what the default behavior is. In this case, "streams are disabled for this table" or something along these lines

*/
streamSpecification?: cloudformation.TableResource.StreamSpecificationProperty;
streamSpecification?: StreamViewType;
}

/**
Expand All @@ -49,14 +50,13 @@ export class Table extends Construct {

const readCapacityUnits = props.readCapacity || 5;
const writeCapacityUnits = props.writeCapacity || 5;
const streamViewType = props.streamSpecification;

this.table = new cloudformation.TableResource(this, 'Resource', {
tableName: props.tableName,
keySchema: this.keySchema,
attributeDefinitions: this.attributeDefinitions,
provisionedThroughput: { readCapacityUnits, writeCapacityUnits },
streamSpecification: streamViewType
streamSpecification: props.streamSpecification ? {streamViewType: props.streamSpecification} : undefined
});

if (props.tableName) { this.addMetadata('aws:cdk:hasPhysicalName', props.tableName); }
Expand Down Expand Up @@ -119,4 +119,21 @@ export enum KeyAttributeType {
Binary = 'B',
Number = 'N',
String = 'S',
}
}

/**
* When an item in the table is modified, StreamViewType determines what information
* is written to the stream for this table. Valid values for StreamViewType are:
* @link https://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_StreamSpecification.html
* @enum {string}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not needed

*/
export enum StreamViewType {
/** The entire item, as it appears after it was modified, is written to the stream. */
NewImage = 'NEW_IMAGE',
/** The entire item, as it appeared before it was modified, is written to the stream. */
OldImage = 'OLD_IMAGE',
/** Both the new and the old item images of the item are written to the stream. */
NewAndOldImages = 'NEW_AND_OLD_IMAGES',
/** Only the key attributes of the modified item are written to the stream. */
KeysOnly = 'KEYS_ONLY'
}
8 changes: 4 additions & 4 deletions packages/@aws-cdk/aws-dynamodb/test/test.dynamodb.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { App, Stack } from '@aws-cdk/cdk';
import { Test } from 'nodeunit';
import { KeyAttributeType, Table } from '../lib';
import { KeyAttributeType, StreamViewType, Table } from '../lib';

export = {
'default properties': {
Expand Down Expand Up @@ -94,7 +94,7 @@ export = {
tableName: 'MyTable',
readCapacity: 42,
writeCapacity: 1337,
streamSpecification: {streamViewType: 'NEW_AND_OLD_IMAGES'}
streamSpecification: StreamViewType.NewAndOldImages
});
table.addPartitionKey('partitionKey', KeyAttributeType.String);
table.addSortKey('sortKey', KeyAttributeType.Binary);
Expand Down Expand Up @@ -129,7 +129,7 @@ export = {
tableName: 'MyTable',
readCapacity: 42,
writeCapacity: 1337,
streamSpecification: {streamViewType: 'NEW_IMAGE'}
streamSpecification: StreamViewType.NewImage
});
table.addPartitionKey('partitionKey', KeyAttributeType.String);
table.addSortKey('sortKey', KeyAttributeType.Binary);
Expand Down Expand Up @@ -164,7 +164,7 @@ export = {
tableName: 'MyTable',
readCapacity: 42,
writeCapacity: 1337,
streamSpecification: {streamViewType: 'OLD_IMAGE'}
streamSpecification: StreamViewType.OldImage
});
table.addPartitionKey('partitionKey', KeyAttributeType.String);
table.addSortKey('sortKey', KeyAttributeType.Binary);
Expand Down