Skip to content

Commit 625c431

Browse files
LeeroyHanniganLee Hannigan
and
Lee Hannigan
authored
feat(dynamodb): add precision timestamp for kinesis stream (#31863)
### Issue # (if applicable) Closes #31761 ### Reason for this change Missing feature for kinesis data streams ### Description of changes Added feature and unit tests ### Description of how you validated changes Unit tests and integ tests included ### Checklist - [X] My code adheres to the [CONTRIBUTING GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and [DESIGN GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md) ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license* --------- Co-authored-by: Lee Hannigan <[email protected]>
1 parent 784c834 commit 625c431

File tree

10 files changed

+98
-29
lines changed

10 files changed

+98
-29
lines changed

packages/@aws-cdk-testing/framework-integ/test/aws-dynamodb/test/integ.dynamodb.kinesis-stream.js.snapshot/aws-cdk-dynamodb-kinesis-stream.assets.json

+3-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk-testing/framework-integ/test/aws-dynamodb/test/integ.dynamodb.kinesis-stream.js.snapshot/aws-cdk-dynamodb-kinesis-stream.template.json

+1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
}
3838
],
3939
"KinesisStreamSpecification": {
40+
"ApproximateCreationDateTimePrecision": "MILLISECOND",
4041
"StreamArn": {
4142
"Fn::GetAtt": [
4243
"Stream790BDEE4",

packages/@aws-cdk-testing/framework-integ/test/aws-dynamodb/test/integ.dynamodb.kinesis-stream.js.snapshot/cdk.out

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk-testing/framework-integ/test/aws-dynamodb/test/integ.dynamodb.kinesis-stream.js.snapshot/integ.json

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk-testing/framework-integ/test/aws-dynamodb/test/integ.dynamodb.kinesis-stream.js.snapshot/manifest.json

+3-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk-testing/framework-integ/test/aws-dynamodb/test/integ.dynamodb.kinesis-stream.js.snapshot/tree.json

+22-21
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk-testing/framework-integ/test/aws-dynamodb/test/integ.dynamodb.kinesis-stream.ts

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ new dynamodb.Table(stack, 'Table', {
1111
partitionKey: { name: 'hashKey', type: dynamodb.AttributeType.STRING },
1212
removalPolicy: cdk.RemovalPolicy.DESTROY,
1313
kinesisStream: stream,
14+
kinesisPrecisionTimestamp: dynamodb.ApproximateCreationDateTimePrecision.MILLISECOND,
1415
});
1516

1617
app.synth();

packages/aws-cdk-lib/aws-dynamodb/TABLE_V1_API.md

+2
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,8 @@ const sortKey = schema.sortKey;
222222

223223
A Kinesis Data Stream can be configured on the DynamoDB table to capture item-level changes.
224224

225+
You can optionally configure the `kinesisPrecisionTimestamp` parameter to specify the precision level of the approximate creation date and time. The allowed values are `MICROSECOND` and `MILLISECOND`. If this parameter is not specified, the default precision is set to `MICROSECOND`.
226+
225227
```ts
226228
import * as kinesis from 'aws-cdk-lib/aws-kinesis';
227229

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

+32-1
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,23 @@ export interface ImportSourceSpecification {
208208
readonly keyPrefix?: string;
209209
}
210210

211+
/**
212+
* The precision associated with the DynamoDB write timestamps that will be replicated to Kinesis.
213+
* The default setting for record timestamp precision is microseconds. You can change this setting at any time.
214+
* @see https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-dynamodb-table-kinesisstreamspecification.html#aws-properties-dynamodb-table-kinesisstreamspecification-properties
215+
*/
216+
export enum ApproximateCreationDateTimePrecision {
217+
/**
218+
* Millisecond precision
219+
*/
220+
MILLISECOND = 'MILLISECOND',
221+
222+
/**
223+
* Microsecond precision
224+
*/
225+
MICROSECOND = 'MICROSECOND',
226+
}
227+
211228
/**
212229
* Properties of a DynamoDB Table
213230
*
@@ -423,6 +440,13 @@ export interface TableProps extends TableOptions {
423440
* @default - no Kinesis Data Stream
424441
*/
425442
readonly kinesisStream?: kinesis.IStream;
443+
444+
/**
445+
* Kinesis Data Stream approximate creation timestamp prescision
446+
*
447+
* @default ApproximateCreationDateTimePrecision.MICROSECOND
448+
*/
449+
readonly kinesisPrecisionTimestamp?: ApproximateCreationDateTimePrecision;
426450
}
427451

428452
/**
@@ -1172,6 +1196,13 @@ export class Table extends TableBase {
11721196
}
11731197
this.validateProvisioning(props);
11741198

1199+
const kinesisStreamSpecification = props.kinesisStream
1200+
? {
1201+
streamArn: props.kinesisStream.streamArn,
1202+
...(props.kinesisPrecisionTimestamp && { approximateCreationDateTimePrecision: props.kinesisPrecisionTimestamp }),
1203+
}
1204+
: undefined;
1205+
11751206
this.table = new CfnTable(this, 'Resource', {
11761207
tableName: this.physicalName,
11771208
keySchema: this.keySchema,
@@ -1196,7 +1227,7 @@ export class Table extends TableBase {
11961227
tableClass: props.tableClass,
11971228
timeToLiveSpecification: props.timeToLiveAttribute ? { attributeName: props.timeToLiveAttribute, enabled: true } : undefined,
11981229
contributorInsightsSpecification: props.contributorInsightsEnabled !== undefined ? { enabled: props.contributorInsightsEnabled } : undefined,
1199-
kinesisStreamSpecification: props.kinesisStream ? { streamArn: props.kinesisStream.streamArn } : undefined,
1230+
kinesisStreamSpecification: kinesisStreamSpecification,
12001231
deletionProtectionEnabled: props.deletionProtection,
12011232
importSourceSpecification: this.renderImportSourceSpecification(props.importSource),
12021233
resourcePolicy: props.resourcePolicy

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

+32
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import {
2424
CfnTable,
2525
InputCompressionType,
2626
InputFormat,
27+
ApproximateCreationDateTimePrecision,
2728
} from '../lib';
2829
import { ReplicaProvider } from '../lib/replica-provider';
2930

@@ -3783,3 +3784,34 @@ test('Warm Throughput test provisioned', () => {
37833784
});
37843785

37853786
});
3787+
3788+
test('Kinesis Stream - precision timestamp', () => {
3789+
// GIVEN
3790+
const app = new App();
3791+
const stack = new Stack(app, 'Stack');
3792+
3793+
const stream = new kinesis.Stream(stack, 'Stream');
3794+
3795+
// WHEN
3796+
const table = new Table(stack, 'Table', {
3797+
partitionKey: { name: 'id', type: AttributeType.STRING },
3798+
kinesisStream: stream,
3799+
kinesisPrecisionTimestamp: ApproximateCreationDateTimePrecision.MILLISECOND,
3800+
});
3801+
3802+
// THEN
3803+
Template.fromStack(stack).hasResourceProperties('AWS::DynamoDB::Table', {
3804+
KeySchema: [
3805+
{ AttributeName: 'id', KeyType: 'HASH' },
3806+
],
3807+
AttributeDefinitions: [
3808+
{ AttributeName: 'id', AttributeType: 'S' },
3809+
],
3810+
KinesisStreamSpecification: {
3811+
StreamArn: {
3812+
'Fn::GetAtt': ['Stream790BDEE4', 'Arn'],
3813+
},
3814+
ApproximateCreationDateTimePrecision: 'MILLISECOND',
3815+
},
3816+
});
3817+
});

0 commit comments

Comments
 (0)