From 277cd85ae6dc75aebb675f88ced665cb6f319257 Mon Sep 17 00:00:00 2001 From: Elad Ben-Israel Date: Tue, 18 Jun 2019 15:42:07 +0300 Subject: [PATCH 1/4] refactor(dynamodb): API cleanups BREAKING CHANGE: `TableOptions.pitrEnabled` renamed to `pointInTimeRecovery`. * **dynamodb:** `TableOptions.sseEnabled` renamed to `serverSideEncryption`. * **dynamodb:** `TableOptions.ttlAttributeName` renamed to `timeToLiveAttribute`. * **dynamodb:** `TableOptions.streamSpecification` renamed `stream`. --- packages/@aws-cdk/aws-dynamodb/lib/table.ts | 22 +++++++++---------- .../test/integ.dynamodb.ondemand.ts | 8 +++---- .../aws-dynamodb/test/integ.dynamodb.ts | 8 +++---- .../aws-dynamodb/test/test.dynamodb.ts | 16 +++++++------- 4 files changed, 27 insertions(+), 27 deletions(-) diff --git a/packages/@aws-cdk/aws-dynamodb/lib/table.ts b/packages/@aws-cdk/aws-dynamodb/lib/table.ts index f5ff1c6f7768d..0b91f28c26cdc 100644 --- a/packages/@aws-cdk/aws-dynamodb/lib/table.ts +++ b/packages/@aws-cdk/aws-dynamodb/lib/table.ts @@ -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; /** * 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 { @@ -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); } diff --git a/packages/@aws-cdk/aws-dynamodb/test/integ.dynamodb.ondemand.ts b/packages/@aws-cdk/aws-dynamodb/test/integ.dynamodb.ondemand.ts index a2e2aec0f876e..38514f6e93a2c 100644 --- a/packages/@aws-cdk/aws-dynamodb/test/integ.dynamodb.ondemand.ts +++ b/packages/@aws-cdk/aws-dynamodb/test/integ.dynamodb.ondemand.ts @@ -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 }); diff --git a/packages/@aws-cdk/aws-dynamodb/test/integ.dynamodb.ts b/packages/@aws-cdk/aws-dynamodb/test/integ.dynamodb.ts index 646332c4748e6..62b135a71152a 100644 --- a/packages/@aws-cdk/aws-dynamodb/test/integ.dynamodb.ts +++ b/packages/@aws-cdk/aws-dynamodb/test/integ.dynamodb.ts @@ -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 }); diff --git a/packages/@aws-cdk/aws-dynamodb/test/test.dynamodb.ts b/packages/@aws-cdk/aws-dynamodb/test/test.dynamodb.ts index b92d3057c17de..01c7a6fcdb3a2 100644 --- a/packages/@aws-cdk/aws-dynamodb/test/test.dynamodb.ts +++ b/packages/@aws-cdk/aws-dynamodb/test/test.dynamodb.ts @@ -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 }); @@ -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 }); @@ -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 }); @@ -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, }); @@ -1179,7 +1179,7 @@ export = { name: 'id', type: AttributeType.String }, - streamSpecification: StreamViewType.NewImage + stream: StreamViewType.NewImage }); const user = new iam.User(stack, 'user'); From c60b9433031b46edf4b59a64919a6e59f79af521 Mon Sep 17 00:00:00 2001 From: Elad Ben-Israel Date: Tue, 18 Jun 2019 16:22:13 +0300 Subject: [PATCH 2/4] fix global --- .../aws-dynamodb-global/lib/aws-dynamodb-global.ts | 8 ++++---- .../aws-dynamodb-global/test/test.dynamodb.global.ts | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/@aws-cdk/aws-dynamodb-global/lib/aws-dynamodb-global.ts b/packages/@aws-cdk/aws-dynamodb-global/lib/aws-dynamodb-global.ts index 89f49f3c95e78..62e7aa72b1d92 100644 --- a/packages/@aws-cdk/aws-dynamodb-global/lib/aws-dynamodb-global.ts +++ b/packages/@aws-cdk/aws-dynamodb-global/lib/aws-dynamodb-global.ts @@ -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 // 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. diff --git a/packages/@aws-cdk/aws-dynamodb-global/test/test.dynamodb.global.ts b/packages/@aws-cdk/aws-dynamodb-global/test/test.dynamodb.global.ts index a9cd979219a1b..56ea1876f3442 100644 --- a/packages/@aws-cdk/aws-dynamodb-global/test/test.dynamodb.global.ts +++ b/packages/@aws-cdk/aws-dynamodb-global/test/test.dynamodb.global.ts @@ -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' ] }); From c294154ce09d3f63ff6a171ea35e97ef6a7cbde8 Mon Sep 17 00:00:00 2001 From: Elad Ben-Israel Date: Tue, 18 Jun 2019 17:12:56 +0300 Subject: [PATCH 3/4] fix some more instances of streamSpec --- packages/@aws-cdk/aws-dynamodb-global/README.md | 2 +- .../aws-dynamodb-global/lib/aws-dynamodb-global.ts | 2 +- packages/@aws-cdk/aws-lambda-event-sources/README.md | 6 +++--- .../aws-lambda-event-sources/test/integ.dynamodb.ts | 2 +- .../@aws-cdk/aws-lambda-event-sources/test/test.dynamo.ts | 8 ++++---- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/packages/@aws-cdk/aws-dynamodb-global/README.md b/packages/@aws-cdk/aws-dynamodb-global/README.md index 3edf3b9d6f288..209698f459fa1 100644 --- a/packages/@aws-cdk/aws-dynamodb-global/README.md +++ b/packages/@aws-cdk/aws-dynamodb-global/README.md @@ -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`. diff --git a/packages/@aws-cdk/aws-dynamodb-global/lib/aws-dynamodb-global.ts b/packages/@aws-cdk/aws-dynamodb-global/lib/aws-dynamodb-global.ts index 62e7aa72b1d92..6a865ded03cc8 100644 --- a/packages/@aws-cdk/aws-dynamodb-global/lib/aws-dynamodb-global.ts +++ b/packages/@aws-cdk/aws-dynamodb-global/lib/aws-dynamodb-global.ts @@ -43,7 +43,7 @@ export class GlobalTable extends cdk.Construct { 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: dynamodb.TableProps = { ...props, diff --git a/packages/@aws-cdk/aws-lambda-event-sources/README.md b/packages/@aws-cdk/aws-lambda-event-sources/README.md index 30844721d2545..c52802020e4a2 100644 --- a/packages/@aws-cdk/aws-lambda-event-sources/README.md +++ b/packages/@aws-cdk/aws-lambda-event-sources/README.md @@ -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 @@ -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(...); diff --git a/packages/@aws-cdk/aws-lambda-event-sources/test/integ.dynamodb.ts b/packages/@aws-cdk/aws-lambda-event-sources/test/integ.dynamodb.ts index 83246fb51e9bd..2c9379dc60acf 100644 --- a/packages/@aws-cdk/aws-lambda-event-sources/test/integ.dynamodb.ts +++ b/packages/@aws-cdk/aws-lambda-event-sources/test/integ.dynamodb.ts @@ -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, { diff --git a/packages/@aws-cdk/aws-lambda-event-sources/test/test.dynamo.ts b/packages/@aws-cdk/aws-lambda-event-sources/test/test.dynamo.ts index 75e7461c35a7d..90afc443559a5 100644 --- a/packages/@aws-cdk/aws-lambda-event-sources/test/test.dynamo.ts +++ b/packages/@aws-cdk/aws-lambda-event-sources/test/test.dynamo.ts @@ -18,7 +18,7 @@ export = { name: 'id', type: dynamodb.AttributeType.String }, - streamSpecification: dynamodb.StreamViewType.NewImage + stream: dynamodb.StreamViewType.NewImage }); // WHEN @@ -84,7 +84,7 @@ export = { name: 'id', type: dynamodb.AttributeType.String }, - streamSpecification: dynamodb.StreamViewType.NewImage + stream: dynamodb.StreamViewType.NewImage }); // WHEN @@ -120,7 +120,7 @@ export = { name: 'id', type: dynamodb.AttributeType.String }, - streamSpecification: dynamodb.StreamViewType.NewImage + stream: dynamodb.StreamViewType.NewImage }); // WHEN @@ -141,7 +141,7 @@ export = { name: 'id', type: dynamodb.AttributeType.String }, - streamSpecification: dynamodb.StreamViewType.NewImage + stream: dynamodb.StreamViewType.NewImage }); // WHEN From 3624fa75980e3c1d121d5359c10e332c0a64575d Mon Sep 17 00:00:00 2001 From: Elad Ben-Israel Date: Tue, 18 Jun 2019 18:22:46 +0300 Subject: [PATCH 4/4] update decdk example --- packages/decdk/examples/lambda-events.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/decdk/examples/lambda-events.json b/packages/decdk/examples/lambda-events.json index e64f46f3f706f..80d367b1e02c6 100644 --- a/packages/decdk/examples/lambda-events.json +++ b/packages/decdk/examples/lambda-events.json @@ -11,7 +11,7 @@ "name": "ID", "type": "String" }, - "streamSpecification": "NewAndOldImages" + "stream": "NewAndOldImages" } }, "HelloWorldFunction": {