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

refactor(dynamodb): API cleanups #2905

Merged
merged 4 commits into from
Jun 18, 2019
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion packages/@aws-cdk/aws-dynamodb-global/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,4 @@ AWS Global DynamoDB Tables is an odd case currently. The way this package works

### Notes

GlobalTable() will set `dynamoProps.streamSpecification` to be `NEW_AND_OLD_IMAGES` since this is a required attribute for AWS Global DynamoDB tables to work. The package will throw an error if any other `streamSpecification` is set in `DynamoDBGlobalStackProps`.
GlobalTable() will set `dynamoProps.stream` to be `NEW_AND_OLD_IMAGES` since this is a required attribute for AWS Global DynamoDB tables to work. The package will throw an error if any other `stream` specification is set in `DynamoDBGlobalStackProps`.
10 changes: 5 additions & 5 deletions packages/@aws-cdk/aws-dynamodb-global/lib/aws-dynamodb-global.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,15 @@ export class GlobalTable extends cdk.Construct {
super(scope, id);
this._regionalTables = [];

if (props.streamSpecification != null && props.streamSpecification !== dynamodb.StreamViewType.NewAndOldImages) {
throw new Error("dynamoProps.streamSpecification MUST be set to dynamodb.StreamViewType.NewAndOldImages");
if (props.stream != null && props.stream !== dynamodb.StreamViewType.NewAndOldImages) {
throw new Error("dynamoProps.stream MUST be set to dynamodb.StreamViewType.NewAndOldImages");
}

// need to set this streamSpecification, otherwise global tables don't work
// need to set this stream specification, otherwise global tables don't work
// And no way to set a default value in an interface
const stackProps = {
const stackProps: dynamodb.TableProps = {
...props,
streamSpecification: dynamodb.StreamViewType.NewAndOldImages
stream: dynamodb.StreamViewType.NewAndOldImages
};

// here we loop through the configured regions.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export = {
try {
new GlobalTable(stack, CONSTRUCT_NAME, {
tableName: TABLE_NAME,
streamSpecification: StreamViewType.KeysOnly,
stream: StreamViewType.KeysOnly,
partitionKey: TABLE_PARTITION_KEY,
regions: [ 'us-east-1', 'us-east-2', 'us-west-2' ]
});
Expand Down
22 changes: 11 additions & 11 deletions packages/@aws-cdk/aws-dynamodb/lib/table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,28 +85,28 @@ export interface TableOptions {

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

/**
* Whether server-side encryption with an AWS managed customer master key is enabled.
* @default undefined, server-side encryption is enabled with an AWS owned customer master key
* @default - server-side encryption is enabled with an AWS owned customer master key
*/
readonly sseEnabled?: boolean;
readonly serverSideEncryption?: boolean;
eladb marked this conversation as resolved.
Show resolved Hide resolved

/**
* The name of TTL attribute.
* @default undefined, TTL is disabled
* @default - TTL is disabled
*/
readonly ttlAttributeName?: string;
readonly timeToLiveAttribute?: string;

/**
* 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:
* @default undefined, streams are disabled
*/
readonly streamSpecification?: StreamViewType;
readonly stream?: StreamViewType;
}

export interface TableProps extends TableOptions {
Expand Down Expand Up @@ -235,15 +235,15 @@ export class Table extends Resource {
attributeDefinitions: this.attributeDefinitions,
globalSecondaryIndexes: Lazy.anyValue({ produce: () => this.globalSecondaryIndexes }, { omitEmptyArray: true }),
localSecondaryIndexes: Lazy.anyValue({ produce: () => this.localSecondaryIndexes }, { omitEmptyArray: true }),
pointInTimeRecoverySpecification: props.pitrEnabled ? { pointInTimeRecoveryEnabled: props.pitrEnabled } : undefined,
pointInTimeRecoverySpecification: props.pointInTimeRecovery ? { pointInTimeRecoveryEnabled: props.pointInTimeRecovery } : undefined,
billingMode: this.billingMode === BillingMode.PayPerRequest ? this.billingMode : undefined,
provisionedThroughput: props.billingMode === BillingMode.PayPerRequest ? undefined : {
readCapacityUnits: props.readCapacity || 5,
writeCapacityUnits: props.writeCapacity || 5
},
sseSpecification: props.sseEnabled ? { sseEnabled: props.sseEnabled } : undefined,
streamSpecification: props.streamSpecification ? { streamViewType: props.streamSpecification } : undefined,
timeToLiveSpecification: props.ttlAttributeName ? { attributeName: props.ttlAttributeName, enabled: true } : undefined
sseSpecification: props.serverSideEncryption ? { sseEnabled: props.serverSideEncryption } : undefined,
streamSpecification: props.stream ? { streamViewType: props.stream } : undefined,
timeToLiveSpecification: props.timeToLiveAttribute ? { attributeName: props.timeToLiveAttribute, enabled: true } : undefined
});

if (props.tableName) { this.node.addMetadata('aws:cdk:hasPhysicalName', props.tableName); }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,11 @@ new Table(stack, TABLE, {
});

const tableWithGlobalAndLocalSecondaryIndex = new Table(stack, TABLE_WITH_GLOBAL_AND_LOCAL_SECONDARY_INDEX, {
pitrEnabled: true,
sseEnabled: true,
streamSpecification: StreamViewType.KeysOnly,
pointInTimeRecovery: true,
serverSideEncryption: true,
stream: StreamViewType.KeysOnly,
billingMode: BillingMode.PayPerRequest,
ttlAttributeName: 'timeToLive',
timeToLiveAttribute: 'timeToLive',
partitionKey: TABLE_PARTITION_KEY,
sortKey: TABLE_SORT_KEY
});
Expand Down
8 changes: 4 additions & 4 deletions packages/@aws-cdk/aws-dynamodb/test/integ.dynamodb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ const table = new Table(stack, TABLE, {
});

const tableWithGlobalAndLocalSecondaryIndex = new Table(stack, TABLE_WITH_GLOBAL_AND_LOCAL_SECONDARY_INDEX, {
pitrEnabled: true,
sseEnabled: true,
streamSpecification: StreamViewType.KeysOnly,
ttlAttributeName: 'timeToLive',
pointInTimeRecovery: true,
serverSideEncryption: true,
stream: StreamViewType.KeysOnly,
timeToLiveAttribute: 'timeToLive',
partitionKey: TABLE_PARTITION_KEY,
sortKey: TABLE_SORT_KEY
});
Expand Down
16 changes: 8 additions & 8 deletions packages/@aws-cdk/aws-dynamodb/test/test.dynamodb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ export = {
tableName: TABLE_NAME,
readCapacity: 42,
writeCapacity: 1337,
streamSpecification: StreamViewType.NewAndOldImages,
stream: StreamViewType.NewAndOldImages,
partitionKey: TABLE_PARTITION_KEY,
sortKey: TABLE_SORT_KEY
});
Expand Down Expand Up @@ -251,7 +251,7 @@ export = {
tableName: TABLE_NAME,
readCapacity: 42,
writeCapacity: 1337,
streamSpecification: StreamViewType.NewImage,
stream: StreamViewType.NewImage,
partitionKey: TABLE_PARTITION_KEY,
sortKey: TABLE_SORT_KEY
});
Expand Down Expand Up @@ -281,7 +281,7 @@ export = {
tableName: TABLE_NAME,
readCapacity: 42,
writeCapacity: 1337,
streamSpecification: StreamViewType.OldImage,
stream: StreamViewType.OldImage,
partitionKey: TABLE_PARTITION_KEY,
sortKey: TABLE_SORT_KEY
});
Expand Down Expand Up @@ -311,11 +311,11 @@ export = {
tableName: TABLE_NAME,
readCapacity: 42,
writeCapacity: 1337,
pitrEnabled: true,
sseEnabled: true,
pointInTimeRecovery: true,
serverSideEncryption: true,
billingMode: BillingMode.Provisioned,
streamSpecification: StreamViewType.KeysOnly,
ttlAttributeName: 'timeToLive',
stream: StreamViewType.KeysOnly,
timeToLiveAttribute: 'timeToLive',
partitionKey: TABLE_PARTITION_KEY,
sortKey: TABLE_SORT_KEY,
});
Expand Down Expand Up @@ -1179,7 +1179,7 @@ export = {
name: 'id',
type: AttributeType.String
},
streamSpecification: StreamViewType.NewImage
stream: StreamViewType.NewImage
});
const user = new iam.User(stack, 'user');

Expand Down
6 changes: 3 additions & 3 deletions packages/@aws-cdk/aws-lambda-event-sources/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,10 @@ CloudWatch.
You can write Lambda functions to process change events from a DynamoDB Table. An event is emitted to a DynamoDB stream (if configured) whenever a write (Put, Delete, Update)
operation is performed against the table. See [Using AWS Lambda with Amazon DynamoDB](https://docs.aws.amazon.com/lambda/latest/dg/with-ddb.html) for more information.

To process events with a Lambda function, first create or update a DynamoDB table and enable a `streamSpecification` configuration. Then, create a `DynamoEventSource`
To process events with a Lambda function, first create or update a DynamoDB table and enable a `stream` specification. Then, create a `DynamoEventSource`
and add it to your Lambda function. The following parameters will impact Amazon DynamoDB's polling behavior:

* __batchSize__: Determines how many records are buffered before invoking your lambnda function - could impact your function's memory usage (if too high) and ability to keep up with incoming data velocity (if too low).
* __batchSize__: Determines how many records are buffered before invoking your lambda function - could impact your function's memory usage (if too high) and ability to keep up with incoming data velocity (if too low).
* __startingPosition__: Will determine where to being consumption, either at the most recent ('LATEST') record or the oldest record ('TRIM_HORIZON'). 'TRIM_HORIZON' will ensure you process all available data, while 'LATEST' will ignore all reocrds that arrived prior to attaching the event source.

```ts
Expand All @@ -124,7 +124,7 @@ import { DynamoEventSource } from '@aws-cdk/aws-lambda-event-sources';

const table = new dynamodb.Table(..., {
partitionKey: ...,
streamSpecification: dynamodb.StreamViewType.NewImage // make sure stream is configured
stream: dynamodb.StreamViewType.NewImage // make sure stream is configured
});

const function = new lambda.Function(...);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class DynamoEventSourceTest extends cdk.Stack {
name: 'id',
type: dynamodb.AttributeType.String
},
streamSpecification: dynamodb.StreamViewType.NewImage
stream: dynamodb.StreamViewType.NewImage
});

fn.addEventSource(new DynamoEventSource(queue, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export = {
name: 'id',
type: dynamodb.AttributeType.String
},
streamSpecification: dynamodb.StreamViewType.NewImage
stream: dynamodb.StreamViewType.NewImage
});

// WHEN
Expand Down Expand Up @@ -84,7 +84,7 @@ export = {
name: 'id',
type: dynamodb.AttributeType.String
},
streamSpecification: dynamodb.StreamViewType.NewImage
stream: dynamodb.StreamViewType.NewImage
});

// WHEN
Expand Down Expand Up @@ -120,7 +120,7 @@ export = {
name: 'id',
type: dynamodb.AttributeType.String
},
streamSpecification: dynamodb.StreamViewType.NewImage
stream: dynamodb.StreamViewType.NewImage
});

// WHEN
Expand All @@ -141,7 +141,7 @@ export = {
name: 'id',
type: dynamodb.AttributeType.String
},
streamSpecification: dynamodb.StreamViewType.NewImage
stream: dynamodb.StreamViewType.NewImage
});

// WHEN
Expand Down
2 changes: 1 addition & 1 deletion packages/decdk/examples/lambda-events.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"name": "ID",
"type": "String"
},
"streamSpecification": "NewAndOldImages"
"stream": "NewAndOldImages"
}
},
"HelloWorldFunction": {
Expand Down