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

feat(dynamodb): add precision timestamp for kinesis stream #31863

Merged
merged 5 commits into from
Dec 10, 2024
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

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
}
],
"KinesisStreamSpecification": {
"ApproximateCreationDateTimePrecision": "MILLISECOND",
"StreamArn": {
"Fn::GetAtt": [
"Stream790BDEE4",
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ new dynamodb.Table(stack, 'Table', {
partitionKey: { name: 'hashKey', type: dynamodb.AttributeType.STRING },
removalPolicy: cdk.RemovalPolicy.DESTROY,
kinesisStream: stream,
kinesisPrecisionTimestamp: dynamodb.ApproximateCreationDateTimePrecision.MILLISECOND,
});

app.synth();
2 changes: 2 additions & 0 deletions packages/aws-cdk-lib/aws-dynamodb/TABLE_V1_API.md
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,8 @@ const sortKey = schema.sortKey;

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

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

```ts
import * as kinesis from 'aws-cdk-lib/aws-kinesis';

Expand Down
33 changes: 32 additions & 1 deletion packages/aws-cdk-lib/aws-dynamodb/lib/table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,23 @@ export interface ImportSourceSpecification {
readonly keyPrefix?: string;
}

/**
* The precision associated with the DynamoDB write timestamps that will be replicated to Kinesis.
* The default setting for record timestamp precision is microseconds. You can change this setting at any time.
* @see https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-dynamodb-table-kinesisstreamspecification.html#aws-properties-dynamodb-table-kinesisstreamspecification-properties
*/
export enum ApproximateCreationDateTimePrecision {
/**
* Millisecond precision
*/
MILLISECOND = 'MILLISECOND',

/**
* Microsecond precision
*/
MICROSECOND = 'MICROSECOND',
}

/**
* Properties of a DynamoDB Table
*
Expand Down Expand Up @@ -423,6 +440,13 @@ export interface TableProps extends TableOptions {
* @default - no Kinesis Data Stream
*/
readonly kinesisStream?: kinesis.IStream;

/**
* Kinesis Data Stream approximate creation timestamp prescision
*
* @default ApproximateCreationDateTimePrecision.MICROSECOND
*/
readonly kinesisPrecisionTimestamp?: ApproximateCreationDateTimePrecision;
}

/**
Expand Down Expand Up @@ -1172,6 +1196,13 @@ export class Table extends TableBase {
}
this.validateProvisioning(props);

const kinesisStreamSpecification = props.kinesisStream
? {
streamArn: props.kinesisStream.streamArn,
...(props.kinesisPrecisionTimestamp && { approximateCreationDateTimePrecision: props.kinesisPrecisionTimestamp }),
}
: undefined;

this.table = new CfnTable(this, 'Resource', {
tableName: this.physicalName,
keySchema: this.keySchema,
Expand All @@ -1196,7 +1227,7 @@ export class Table extends TableBase {
tableClass: props.tableClass,
timeToLiveSpecification: props.timeToLiveAttribute ? { attributeName: props.timeToLiveAttribute, enabled: true } : undefined,
contributorInsightsSpecification: props.contributorInsightsEnabled !== undefined ? { enabled: props.contributorInsightsEnabled } : undefined,
kinesisStreamSpecification: props.kinesisStream ? { streamArn: props.kinesisStream.streamArn } : undefined,
kinesisStreamSpecification: kinesisStreamSpecification,
deletionProtectionEnabled: props.deletionProtection,
importSourceSpecification: this.renderImportSourceSpecification(props.importSource),
resourcePolicy: props.resourcePolicy
Expand Down
32 changes: 32 additions & 0 deletions packages/aws-cdk-lib/aws-dynamodb/test/dynamodb.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
CfnTable,
InputCompressionType,
InputFormat,
ApproximateCreationDateTimePrecision,
} from '../lib';
import { ReplicaProvider } from '../lib/replica-provider';

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

});

test('Kinesis Stream - precision timestamp', () => {
// GIVEN
const app = new App();
const stack = new Stack(app, 'Stack');

const stream = new kinesis.Stream(stack, 'Stream');

// WHEN
const table = new Table(stack, 'Table', {
partitionKey: { name: 'id', type: AttributeType.STRING },
kinesisStream: stream,
kinesisPrecisionTimestamp: ApproximateCreationDateTimePrecision.MILLISECOND,
});

// THEN
Template.fromStack(stack).hasResourceProperties('AWS::DynamoDB::Table', {
KeySchema: [
{ AttributeName: 'id', KeyType: 'HASH' },
],
AttributeDefinitions: [
{ AttributeName: 'id', AttributeType: 'S' },
],
KinesisStreamSpecification: {
StreamArn: {
'Fn::GetAtt': ['Stream790BDEE4', 'Arn'],
},
ApproximateCreationDateTimePrecision: 'MILLISECOND',
},
});
});
Loading