Skip to content

Commit 6ab7aa1

Browse files
committed
Add line in readme, add token check
1 parent 15381ec commit 6ab7aa1

File tree

3 files changed

+44
-5
lines changed

3 files changed

+44
-5
lines changed

packages/@aws-cdk/aws-pipes-targets-alpha/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ The following targets are supported:
3232
1. `targets.SqsTarget`: [Send event source to a Queue](#amazon-sqs)
3333
2. `targets.SfnStateMachine`: [Invoke a State Machine from an event source](#aws-step-functions-state-machine)
3434
3. `targets.LambdaFunction`: [Send event source to a Lambda Function](#aws-lambda-function)
35+
4. `targets.KinesisTarget`: [Send event source to a Kinesis data stream](#amazon-kinesis-data-stream)
3536

3637
### Amazon SQS
3738

packages/@aws-cdk/aws-pipes-targets-alpha/lib/kinesis.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { IInputTransformation, IPipe, ITarget, TargetConfig } from '@aws-cdk/aws-pipes-alpha';
2+
import { Token } from 'aws-cdk-lib';
23
import { IRole } from 'aws-cdk-lib/aws-iam';
34
import { IStream } from 'aws-cdk-lib/aws-kinesis';
45

@@ -59,7 +60,9 @@ export class KinesisTarget implements ITarget {
5960
}
6061

6162
function validatePartitionKey(pk: string) {
62-
if (pk.length > 256) {
63-
throw new Error(`Partition key must be less than or equal to 256 characters, received ${pk.length}`);
63+
if (!Token.isUnresolved(pk)) {
64+
if (pk.length > 256) {
65+
throw new Error(`Partition key must be less than or equal to 256 characters, received ${pk.length}`);
66+
}
6467
}
6568
}

packages/@aws-cdk/aws-pipes-targets-alpha/test/kinesis.test.ts

+38-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { InputTransformation, Pipe } from '@aws-cdk/aws-pipes-alpha';
2-
import { App, Stack } from 'aws-cdk-lib';
2+
import { App, Lazy, Stack } from 'aws-cdk-lib';
33
import { Template } from 'aws-cdk-lib/assertions';
44
import { Stream } from 'aws-cdk-lib/aws-kinesis';
55
import { TestSource } from './test-classes';
@@ -94,8 +94,8 @@ describe('Kinesis', () => {
9494
});
9595
});
9696

97-
describe('Kinesis source parameters validation', () => {
98-
test('Detail type must be <= 256 characters', () => {
97+
describe('Kinesis target parameters validation', () => {
98+
test('Partition key must be <= 256 characters', () => {
9999
// GIVEN
100100
const app = new App();
101101
const stack = new Stack(app, 'TestStack');
@@ -108,4 +108,39 @@ describe('Kinesis source parameters validation', () => {
108108
});
109109
}).toThrow('Partition key must be less than or equal to 256 characters, received 257');
110110
});
111+
112+
test('Partition key can be given for a token', () => {
113+
// ARRANGE
114+
const app = new App();
115+
const stack = new Stack(app, 'TestStack');
116+
const stream = new Stream(stack, 'MyStream', {});
117+
const partitionKey = Lazy.string({ produce: () => '20' });
118+
119+
const target = new KinesisTarget(stream, {
120+
partitionKey,
121+
});
122+
123+
new Pipe(stack, 'MyPipe', {
124+
source: new TestSource(),
125+
target,
126+
});
127+
128+
// ACT
129+
const template = Template.fromStack(stack);
130+
131+
// ASSERT
132+
template.hasResourceProperties('AWS::Pipes::Pipe', {
133+
Target: {
134+
'Fn::GetAtt': [
135+
'MyStream5C050E93',
136+
'Arn',
137+
],
138+
},
139+
TargetParameters: {
140+
KinesisStreamParameters: {
141+
PartitionKey: '20',
142+
},
143+
},
144+
});
145+
});
111146
});

0 commit comments

Comments
 (0)