Skip to content

Commit

Permalink
Add line in readme, add token check
Browse files Browse the repository at this point in the history
  • Loading branch information
msambol committed Sep 5, 2024
1 parent 15381ec commit 6ab7aa1
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 5 deletions.
1 change: 1 addition & 0 deletions packages/@aws-cdk/aws-pipes-targets-alpha/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ The following targets are supported:
1. `targets.SqsTarget`: [Send event source to a Queue](#amazon-sqs)
2. `targets.SfnStateMachine`: [Invoke a State Machine from an event source](#aws-step-functions-state-machine)
3. `targets.LambdaFunction`: [Send event source to a Lambda Function](#aws-lambda-function)
4. `targets.KinesisTarget`: [Send event source to a Kinesis data stream](#amazon-kinesis-data-stream)

### Amazon SQS

Expand Down
7 changes: 5 additions & 2 deletions packages/@aws-cdk/aws-pipes-targets-alpha/lib/kinesis.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { IInputTransformation, IPipe, ITarget, TargetConfig } from '@aws-cdk/aws-pipes-alpha';
import { Token } from 'aws-cdk-lib';
import { IRole } from 'aws-cdk-lib/aws-iam';
import { IStream } from 'aws-cdk-lib/aws-kinesis';

Expand Down Expand Up @@ -59,7 +60,9 @@ export class KinesisTarget implements ITarget {
}

function validatePartitionKey(pk: string) {
if (pk.length > 256) {
throw new Error(`Partition key must be less than or equal to 256 characters, received ${pk.length}`);
if (!Token.isUnresolved(pk)) {
if (pk.length > 256) {
throw new Error(`Partition key must be less than or equal to 256 characters, received ${pk.length}`);
}
}
}
41 changes: 38 additions & 3 deletions packages/@aws-cdk/aws-pipes-targets-alpha/test/kinesis.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { InputTransformation, Pipe } from '@aws-cdk/aws-pipes-alpha';
import { App, Stack } from 'aws-cdk-lib';
import { App, Lazy, Stack } from 'aws-cdk-lib';
import { Template } from 'aws-cdk-lib/assertions';
import { Stream } from 'aws-cdk-lib/aws-kinesis';
import { TestSource } from './test-classes';
Expand Down Expand Up @@ -94,8 +94,8 @@ describe('Kinesis', () => {
});
});

describe('Kinesis source parameters validation', () => {
test('Detail type must be <= 256 characters', () => {
describe('Kinesis target parameters validation', () => {
test('Partition key must be <= 256 characters', () => {
// GIVEN
const app = new App();
const stack = new Stack(app, 'TestStack');
Expand All @@ -108,4 +108,39 @@ describe('Kinesis source parameters validation', () => {
});
}).toThrow('Partition key must be less than or equal to 256 characters, received 257');
});

test('Partition key can be given for a token', () => {
// ARRANGE
const app = new App();
const stack = new Stack(app, 'TestStack');
const stream = new Stream(stack, 'MyStream', {});
const partitionKey = Lazy.string({ produce: () => '20' });

const target = new KinesisTarget(stream, {
partitionKey,
});

new Pipe(stack, 'MyPipe', {
source: new TestSource(),
target,
});

// ACT
const template = Template.fromStack(stack);

// ASSERT
template.hasResourceProperties('AWS::Pipes::Pipe', {
Target: {
'Fn::GetAtt': [
'MyStream5C050E93',
'Arn',
],
},
TargetParameters: {
KinesisStreamParameters: {
PartitionKey: '20',
},
},
});
});
});

0 comments on commit 6ab7aa1

Please sign in to comment.