Skip to content

Commit b265e46

Browse files
authored
feat(aws-kinesis): add support for data streams capacity modes (#18074)
The latest CloudFormation spec (v51) added support for selecting a capacity mode for Kinesis Data Streams. This is already supported by the generated L1 construct. This change adds support for the feature to the L2 construct class `Stream` via the constructor props `StreamProps`. closes #18050 ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent 19a287f commit b265e46

File tree

2 files changed

+86
-1
lines changed

2 files changed

+86
-1
lines changed

packages/@aws-cdk/aws-kinesis/lib/stream.ts

+28
Original file line numberDiff line numberDiff line change
@@ -699,6 +699,13 @@ export interface StreamProps {
699699
* will be created and associated with this stream.
700700
*/
701701
readonly encryptionKey?: kms.IKey;
702+
703+
/**
704+
* The capacity mode of this stream.
705+
*
706+
* @default StreamMode.PROVISIONED
707+
*/
708+
readonly streamMode?: StreamMode;
702709
}
703710

704711
/**
@@ -746,6 +753,9 @@ export class Stream extends StreamBase {
746753
});
747754

748755
const shardCount = props.shardCount || 1;
756+
757+
const streamMode = props.streamMode;
758+
749759
const retentionPeriodHours = props.retentionPeriod?.toHours() ?? 24;
750760
if (!Token.isUnresolved(retentionPeriodHours)) {
751761
if (retentionPeriodHours < 24 || retentionPeriodHours > 8760) {
@@ -760,6 +770,7 @@ export class Stream extends StreamBase {
760770
retentionPeriodHours,
761771
shardCount,
762772
streamEncryption,
773+
streamModeDetails: streamMode ? { streamMode } : undefined,
763774
});
764775

765776
this.streamArn = this.getResourceArnAttribute(this.stream.attrArn, {
@@ -858,3 +869,20 @@ export enum StreamEncryption {
858869
*/
859870
MANAGED = 'MANAGED'
860871
}
872+
873+
/**
874+
* Specifies the capacity mode to apply to this stream.
875+
*/
876+
export enum StreamMode {
877+
/**
878+
* Specify the provisioned capacity mode. The stream will have `shardCount` shards unless
879+
* modified and will be billed according to the provisioned capacity.
880+
*/
881+
PROVISIONED = 'PROVISIONED',
882+
883+
/**
884+
* Specify the on-demand capacity mode. The stream will autoscale and be billed according to the
885+
* volume of data ingested and retrieved.
886+
*/
887+
ON_DEMAND = 'ON_DEMAND'
888+
}

packages/@aws-cdk/aws-kinesis/test/stream.test.ts

+58-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import * as kms from '@aws-cdk/aws-kms';
55
import { testFutureBehavior, testLegacyBehavior } from '@aws-cdk/cdk-build-tools';
66
import { App, Duration, Stack, CfnParameter } from '@aws-cdk/core';
77
import * as cxapi from '@aws-cdk/cx-api';
8-
import { Stream, StreamEncryption } from '../lib';
8+
import { Stream, StreamEncryption, StreamMode } from '../lib';
99

1010
/* eslint-disable quote-props */
1111

@@ -374,6 +374,63 @@ describe('Kinesis data streams', () => {
374374
});
375375
}),
376376

377+
test.each([StreamMode.ON_DEMAND, StreamMode.PROVISIONED])('uses explicit capacity mode %s', (mode: StreamMode) => {
378+
const stack = new Stack();
379+
380+
new Stream(stack, 'MyStream', {
381+
streamMode: mode,
382+
});
383+
384+
expect(stack).toMatchTemplate({
385+
Resources: {
386+
MyStream5C050E93: {
387+
Type: 'AWS::Kinesis::Stream',
388+
Properties: {
389+
ShardCount: 1,
390+
RetentionPeriodHours: 24,
391+
StreamModeDetails: {
392+
StreamMode: StreamMode[mode],
393+
},
394+
StreamEncryption: {
395+
'Fn::If': [
396+
'AwsCdkKinesisEncryptedStreamsUnsupportedRegions',
397+
{
398+
Ref: 'AWS::NoValue',
399+
},
400+
{
401+
EncryptionType: 'KMS',
402+
KeyId: 'alias/aws/kinesis',
403+
},
404+
],
405+
},
406+
},
407+
},
408+
},
409+
Conditions: {
410+
AwsCdkKinesisEncryptedStreamsUnsupportedRegions: {
411+
'Fn::Or': [
412+
{
413+
'Fn::Equals': [
414+
{
415+
Ref: 'AWS::Region',
416+
},
417+
'cn-north-1',
418+
],
419+
},
420+
{
421+
'Fn::Equals': [
422+
{
423+
Ref: 'AWS::Region',
424+
},
425+
'cn-northwest-1',
426+
],
427+
},
428+
],
429+
},
430+
},
431+
});
432+
});
433+
377434
test('grantRead creates and attaches a policy with read only access to the principal', () => {
378435
const stack = new Stack();
379436
const stream = new Stream(stack, 'MyStream', {

0 commit comments

Comments
 (0)