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): adding kinesis timestamp precision #31761

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
17 changes: 17 additions & 0 deletions packages/aws-cdk-lib/aws-dynamodb/lib/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,23 @@ export enum StreamViewType {
KEYS_ONLY = 'KEYS_ONLY',
}

/**
* 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 for a secondary index
*/
Expand Down
20 changes: 16 additions & 4 deletions packages/aws-cdk-lib/aws-dynamodb/lib/table-v2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Capacity } from './capacity';
import { CfnGlobalTable } from './dynamodb.generated';
import { TableEncryptionV2 } from './encryption';
import {
StreamViewType,
StreamViewType, ApproximateCreationDateTimePrecision,
Attribute, TableClass, LocalSecondaryIndexProps,
SecondaryIndexProps, BillingMode, ProjectionType,
} from './shared';
Expand Down Expand Up @@ -143,6 +143,13 @@ export interface TableOptionsV2 {
*/
readonly kinesisStream?: IStream;

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

/**
* Tags to be applied to the table or replica table
*
Expand Down Expand Up @@ -665,16 +672,20 @@ export class TableV2 extends TableBaseV2 {
const pointInTimeRecovery = props.pointInTimeRecovery ?? this.tableOptions.pointInTimeRecovery;
const contributorInsights = props.contributorInsights ?? this.tableOptions.contributorInsights;
const resourcePolicy = props.resourcePolicy ?? this.tableOptions.resourcePolicy;
const kinesisStreamSpecification = props.kinesisStream
? {
streamArn: props.kinesisStream.streamArn,
...(props.kinesisPrecisionTimestamp && { approximateCreationDateTimePrecision: props.kinesisPrecisionTimestamp }),
}
: undefined;

return {
region: props.region,
globalSecondaryIndexes: this.configureReplicaGlobalSecondaryIndexes(props.globalSecondaryIndexOptions),
deletionProtectionEnabled: props.deletionProtection ?? this.tableOptions.deletionProtection,
tableClass: props.tableClass ?? this.tableOptions.tableClass,
sseSpecification: this.encryption?._renderReplicaSseSpecification(this, props.region),
kinesisStreamSpecification: props.kinesisStream
? { streamArn: props.kinesisStream.streamArn }
: undefined,
kinesisStreamSpecification: kinesisStreamSpecification,
contributorInsightsSpecification: contributorInsights !== undefined
? { enabled: contributorInsights }
: undefined,
Expand Down Expand Up @@ -810,6 +821,7 @@ export class TableV2 extends TableBaseV2 {
replicaTables.push(this.configureReplicaTable({
region: this.stack.region,
kinesisStream: this.tableOptions.kinesisStream,
kinesisPrecisionTimestamp: this.tableOptions.kinesisPrecisionTimestamp,
tags: this.tableOptions.tags,
}));

Expand Down
54 changes: 54 additions & 0 deletions packages/aws-cdk-lib/aws-dynamodb/test/table-v2.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { CfnDeletionPolicy, Lazy, RemovalPolicy, Stack } from '../../core';
import {
AttributeType, Billing, Capacity, GlobalSecondaryIndexPropsV2, TableV2,
LocalSecondaryIndexProps, ProjectionType, StreamViewType, TableClass, TableEncryptionV2,
ApproximateCreationDateTimePrecision,
} from '../lib';

describe('table', () => {
Expand Down Expand Up @@ -1342,6 +1343,59 @@ describe('replica tables', () => {
});
});

test('with per-replica kinesis stream with precision creation timestamp', () => {
// GIVEN
const stack = new Stack(undefined, 'Stack', { env: { region: 'us-west-2' } });
const kinesisStream1 = new Stream(stack, 'Stream1');
const kinesisStream2 = Stream.fromStreamArn(stack, 'Stream2', 'arn:aws:kinesis:us-east-1:123456789012:stream/my-stream');

// WHEN
new TableV2(stack, 'GlobalTable', {
partitionKey: { name: 'pk', type: AttributeType.STRING },
kinesisStream: kinesisStream1,
kinesisPrecisionTimestamp: ApproximateCreationDateTimePrecision.MICROSECOND,
replicas: [
{
region: 'us-east-1',
kinesisStream: kinesisStream2,
kinesisPrecisionTimestamp: ApproximateCreationDateTimePrecision.MILLISECOND,
},
{
region: 'us-east-2',
},
],
});

// THEN
Template.fromStack(stack).hasResourceProperties('AWS::DynamoDB::GlobalTable', {
Replicas: [
{
Region: 'us-east-1',
KinesisStreamSpecification: {
StreamArn: 'arn:aws:kinesis:us-east-1:123456789012:stream/my-stream',
ApproximateCreationDateTimePrecision: 'MILLISECOND',
},
},
{
Region: 'us-east-2',
KinesisStreamSpecification: Match.absent(),
},
{
Region: 'us-west-2',
KinesisStreamSpecification: {
StreamArn: {
'Fn::GetAtt': [
'Stream16C8F97AF',
'Arn',
],
},
ApproximateCreationDateTimePrecision: 'MICROSECOND',
},
},
],
});
});

test('with per-replica contributor insights on global secondary index', () => {
// GIVEN
const stack = new Stack(undefined, 'Stack', { env: { region: 'us-west-2' } });
Expand Down
Loading