Skip to content

Commit d229836

Browse files
author
Elad Ben-Israel
authored
refactor(dynamodb): API cleanups (#2905)
BREAKING CHANGE: `TableOptions.pitrEnabled` renamed to `pointInTimeRecovery`. * **dynamodb:** `TableOptions.sseEnabled` renamed to `serverSideEncryption`. * **dynamodb:** `TableOptions.ttlAttributeName` renamed to `timeToLiveAttribute`. * **dynamodb:** `TableOptions.streamSpecification` renamed `stream`.
1 parent 7c6ebb6 commit d229836

File tree

11 files changed

+43
-43
lines changed

11 files changed

+43
-43
lines changed

packages/@aws-cdk/aws-dynamodb-global/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,4 @@ AWS Global DynamoDB Tables is an odd case currently. The way this package works
3838

3939
### Notes
4040

41-
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`.
41+
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`.

packages/@aws-cdk/aws-dynamodb-global/lib/aws-dynamodb-global.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,15 @@ export class GlobalTable extends cdk.Construct {
3939
super(scope, id);
4040
this._regionalTables = [];
4141

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

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

5353
// here we loop through the configured regions.

packages/@aws-cdk/aws-dynamodb-global/test/test.dynamodb.global.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ export = {
7171
try {
7272
new GlobalTable(stack, CONSTRUCT_NAME, {
7373
tableName: TABLE_NAME,
74-
streamSpecification: StreamViewType.KeysOnly,
74+
stream: StreamViewType.KeysOnly,
7575
partitionKey: TABLE_PARTITION_KEY,
7676
regions: [ 'us-east-1', 'us-east-2', 'us-west-2' ]
7777
});

packages/@aws-cdk/aws-dynamodb/lib/table.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -85,28 +85,28 @@ export interface TableOptions {
8585

8686
/**
8787
* Whether point-in-time recovery is enabled.
88-
* @default undefined, point-in-time recovery is disabled
88+
* @default - point-in-time recovery is disabled
8989
*/
90-
readonly pitrEnabled?: boolean;
90+
readonly pointInTimeRecovery?: boolean;
9191

9292
/**
9393
* Whether server-side encryption with an AWS managed customer master key is enabled.
94-
* @default undefined, server-side encryption is enabled with an AWS owned customer master key
94+
* @default - server-side encryption is enabled with an AWS owned customer master key
9595
*/
96-
readonly sseEnabled?: boolean;
96+
readonly serverSideEncryption?: boolean;
9797

9898
/**
9999
* The name of TTL attribute.
100-
* @default undefined, TTL is disabled
100+
* @default - TTL is disabled
101101
*/
102-
readonly ttlAttributeName?: string;
102+
readonly timeToLiveAttribute?: string;
103103

104104
/**
105105
* When an item in the table is modified, StreamViewType determines what information
106106
* is written to the stream for this table. Valid values for StreamViewType are:
107107
* @default undefined, streams are disabled
108108
*/
109-
readonly streamSpecification?: StreamViewType;
109+
readonly stream?: StreamViewType;
110110
}
111111

112112
export interface TableProps extends TableOptions {
@@ -235,15 +235,15 @@ export class Table extends Resource {
235235
attributeDefinitions: this.attributeDefinitions,
236236
globalSecondaryIndexes: Lazy.anyValue({ produce: () => this.globalSecondaryIndexes }, { omitEmptyArray: true }),
237237
localSecondaryIndexes: Lazy.anyValue({ produce: () => this.localSecondaryIndexes }, { omitEmptyArray: true }),
238-
pointInTimeRecoverySpecification: props.pitrEnabled ? { pointInTimeRecoveryEnabled: props.pitrEnabled } : undefined,
238+
pointInTimeRecoverySpecification: props.pointInTimeRecovery ? { pointInTimeRecoveryEnabled: props.pointInTimeRecovery } : undefined,
239239
billingMode: this.billingMode === BillingMode.PayPerRequest ? this.billingMode : undefined,
240240
provisionedThroughput: props.billingMode === BillingMode.PayPerRequest ? undefined : {
241241
readCapacityUnits: props.readCapacity || 5,
242242
writeCapacityUnits: props.writeCapacity || 5
243243
},
244-
sseSpecification: props.sseEnabled ? { sseEnabled: props.sseEnabled } : undefined,
245-
streamSpecification: props.streamSpecification ? { streamViewType: props.streamSpecification } : undefined,
246-
timeToLiveSpecification: props.ttlAttributeName ? { attributeName: props.ttlAttributeName, enabled: true } : undefined
244+
sseSpecification: props.serverSideEncryption ? { sseEnabled: props.serverSideEncryption } : undefined,
245+
streamSpecification: props.stream ? { streamViewType: props.stream } : undefined,
246+
timeToLiveSpecification: props.timeToLiveAttribute ? { attributeName: props.timeToLiveAttribute, enabled: true } : undefined
247247
});
248248

249249
if (props.tableName) { this.node.addMetadata('aws:cdk:hasPhysicalName', props.tableName); }

packages/@aws-cdk/aws-dynamodb/test/integ.dynamodb.ondemand.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,11 @@ new Table(stack, TABLE, {
4747
});
4848

4949
const tableWithGlobalAndLocalSecondaryIndex = new Table(stack, TABLE_WITH_GLOBAL_AND_LOCAL_SECONDARY_INDEX, {
50-
pitrEnabled: true,
51-
sseEnabled: true,
52-
streamSpecification: StreamViewType.KeysOnly,
50+
pointInTimeRecovery: true,
51+
serverSideEncryption: true,
52+
stream: StreamViewType.KeysOnly,
5353
billingMode: BillingMode.PayPerRequest,
54-
ttlAttributeName: 'timeToLive',
54+
timeToLiveAttribute: 'timeToLive',
5555
partitionKey: TABLE_PARTITION_KEY,
5656
sortKey: TABLE_SORT_KEY
5757
});

packages/@aws-cdk/aws-dynamodb/test/integ.dynamodb.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,10 @@ const table = new Table(stack, TABLE, {
4646
});
4747

4848
const tableWithGlobalAndLocalSecondaryIndex = new Table(stack, TABLE_WITH_GLOBAL_AND_LOCAL_SECONDARY_INDEX, {
49-
pitrEnabled: true,
50-
sseEnabled: true,
51-
streamSpecification: StreamViewType.KeysOnly,
52-
ttlAttributeName: 'timeToLive',
49+
pointInTimeRecovery: true,
50+
serverSideEncryption: true,
51+
stream: StreamViewType.KeysOnly,
52+
timeToLiveAttribute: 'timeToLive',
5353
partitionKey: TABLE_PARTITION_KEY,
5454
sortKey: TABLE_SORT_KEY
5555
});

packages/@aws-cdk/aws-dynamodb/test/test.dynamodb.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ export = {
222222
tableName: TABLE_NAME,
223223
readCapacity: 42,
224224
writeCapacity: 1337,
225-
streamSpecification: StreamViewType.NewAndOldImages,
225+
stream: StreamViewType.NewAndOldImages,
226226
partitionKey: TABLE_PARTITION_KEY,
227227
sortKey: TABLE_SORT_KEY
228228
});
@@ -252,7 +252,7 @@ export = {
252252
tableName: TABLE_NAME,
253253
readCapacity: 42,
254254
writeCapacity: 1337,
255-
streamSpecification: StreamViewType.NewImage,
255+
stream: StreamViewType.NewImage,
256256
partitionKey: TABLE_PARTITION_KEY,
257257
sortKey: TABLE_SORT_KEY
258258
});
@@ -282,7 +282,7 @@ export = {
282282
tableName: TABLE_NAME,
283283
readCapacity: 42,
284284
writeCapacity: 1337,
285-
streamSpecification: StreamViewType.OldImage,
285+
stream: StreamViewType.OldImage,
286286
partitionKey: TABLE_PARTITION_KEY,
287287
sortKey: TABLE_SORT_KEY
288288
});
@@ -312,11 +312,11 @@ export = {
312312
tableName: TABLE_NAME,
313313
readCapacity: 42,
314314
writeCapacity: 1337,
315-
pitrEnabled: true,
316-
sseEnabled: true,
315+
pointInTimeRecovery: true,
316+
serverSideEncryption: true,
317317
billingMode: BillingMode.Provisioned,
318-
streamSpecification: StreamViewType.KeysOnly,
319-
ttlAttributeName: 'timeToLive',
318+
stream: StreamViewType.KeysOnly,
319+
timeToLiveAttribute: 'timeToLive',
320320
partitionKey: TABLE_PARTITION_KEY,
321321
sortKey: TABLE_SORT_KEY,
322322
});
@@ -1180,7 +1180,7 @@ export = {
11801180
name: 'id',
11811181
type: AttributeType.String
11821182
},
1183-
streamSpecification: StreamViewType.NewImage
1183+
stream: StreamViewType.NewImage
11841184
});
11851185
const user = new iam.User(stack, 'user');
11861186

packages/@aws-cdk/aws-lambda-event-sources/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,10 +111,10 @@ CloudWatch.
111111
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)
112112
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.
113113
114-
To process events with a Lambda function, first create or update a DynamoDB table and enable a `streamSpecification` configuration. Then, create a `DynamoEventSource`
114+
To process events with a Lambda function, first create or update a DynamoDB table and enable a `stream` specification. Then, create a `DynamoEventSource`
115115
and add it to your Lambda function. The following parameters will impact Amazon DynamoDB's polling behavior:
116116
117-
* __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).
117+
* __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).
118118
* __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.
119119
120120
```ts
@@ -124,7 +124,7 @@ import { DynamoEventSource } from '@aws-cdk/aws-lambda-event-sources';
124124

125125
const table = new dynamodb.Table(..., {
126126
partitionKey: ...,
127-
streamSpecification: dynamodb.StreamViewType.NewImage // make sure stream is configured
127+
stream: dynamodb.StreamViewType.NewImage // make sure stream is configured
128128
});
129129

130130
const function = new lambda.Function(...);

packages/@aws-cdk/aws-lambda-event-sources/test/integ.dynamodb.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class DynamoEventSourceTest extends cdk.Stack {
1414
name: 'id',
1515
type: dynamodb.AttributeType.String
1616
},
17-
streamSpecification: dynamodb.StreamViewType.NewImage
17+
stream: dynamodb.StreamViewType.NewImage
1818
});
1919

2020
fn.addEventSource(new DynamoEventSource(queue, {

packages/@aws-cdk/aws-lambda-event-sources/test/test.dynamo.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export = {
1818
name: 'id',
1919
type: dynamodb.AttributeType.String
2020
},
21-
streamSpecification: dynamodb.StreamViewType.NewImage
21+
stream: dynamodb.StreamViewType.NewImage
2222
});
2323

2424
// WHEN
@@ -84,7 +84,7 @@ export = {
8484
name: 'id',
8585
type: dynamodb.AttributeType.String
8686
},
87-
streamSpecification: dynamodb.StreamViewType.NewImage
87+
stream: dynamodb.StreamViewType.NewImage
8888
});
8989

9090
// WHEN
@@ -120,7 +120,7 @@ export = {
120120
name: 'id',
121121
type: dynamodb.AttributeType.String
122122
},
123-
streamSpecification: dynamodb.StreamViewType.NewImage
123+
stream: dynamodb.StreamViewType.NewImage
124124
});
125125

126126
// WHEN
@@ -141,7 +141,7 @@ export = {
141141
name: 'id',
142142
type: dynamodb.AttributeType.String
143143
},
144-
streamSpecification: dynamodb.StreamViewType.NewImage
144+
stream: dynamodb.StreamViewType.NewImage
145145
});
146146

147147
// WHEN

0 commit comments

Comments
 (0)