-
Notifications
You must be signed in to change notification settings - Fork 4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(pipes-targets): add Kinesis (#30656)
Add Kinesis data stream as a Pipes target. It's nontrivial to get the data from the Kinesis data stream, but here are screenshots showing data made it through during the integration test. <img width="656" alt="Screenshot 2024-06-24 at 7 24 10 PM" src="https://github.com/aws/aws-cdk/assets/3310356/bc6e12a2-8fea-42a7-baaa-e8b5b5ea652f"> <img width="649" alt="Screenshot 2024-06-24 at 7 26 35 PM" src="https://github.com/aws/aws-cdk/assets/3310356/5224b0d9-a356-47e6-ab48-3551ff3b5078">
- Loading branch information
Showing
16 changed files
with
33,157 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
export * from './api-destination'; | ||
export * from './kinesis'; | ||
export * from './lambda'; | ||
export * from './sqs'; | ||
export * from './stepfunctions'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
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'; | ||
|
||
/** | ||
* Kinesis target properties. | ||
*/ | ||
export interface KinesisTargetParameters { | ||
/** | ||
* The input transformation to apply to the message before sending it to the target. | ||
* | ||
* @see https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-pipes-pipe-pipetargetparameters.html#cfn-pipes-pipe-pipetargetparameters-inputtemplate | ||
* @default - none | ||
*/ | ||
readonly inputTransformation?: IInputTransformation; | ||
|
||
/** | ||
* Determines which shard in the stream the data record is assigned to. | ||
* | ||
* @see https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-pipes-pipe-pipetargetkinesisstreamparameters.html#cfn-pipes-pipe-pipetargetkinesisstreamparameters-partitionkey | ||
*/ | ||
readonly partitionKey: string; | ||
} | ||
|
||
/** | ||
* An EventBridge Pipes target that sends messages to a Kinesis stream. | ||
*/ | ||
export class KinesisTarget implements ITarget { | ||
private stream: IStream; | ||
private streamParameters: KinesisTargetParameters; | ||
public readonly targetArn: string; | ||
|
||
constructor(stream: IStream, parameters: KinesisTargetParameters) { | ||
this.stream = stream; | ||
this.targetArn = stream.streamArn; | ||
this.streamParameters = parameters; | ||
|
||
validatePartitionKey(parameters.partitionKey); | ||
} | ||
|
||
grantPush(grantee: IRole): void { | ||
this.stream.grantWrite(grantee); | ||
} | ||
|
||
bind(pipe: IPipe): TargetConfig { | ||
return { | ||
targetParameters: { | ||
inputTemplate: this.streamParameters.inputTransformation?.bind(pipe).inputTemplate, | ||
kinesisStreamParameters: this.streamParameters, | ||
}, | ||
}; | ||
} | ||
} | ||
|
||
function validatePartitionKey(pk: string) { | ||
if (!Token.isUnresolved(pk) && pk.length > 256) { | ||
throw new Error(`Partition key must be less than or equal to 256 characters, received ${pk.length}`); | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
packages/@aws-cdk/aws-pipes-targets-alpha/rosetta/default.ts-fixture
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
packages/@aws-cdk/aws-pipes-targets-alpha/test/__snapshots__/kinesis.test.ts.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`Kinesis should grant pipe role push access 1`] = ` | ||
{ | ||
"MyPipeRoleCBC8E9AB": { | ||
"Properties": { | ||
"AssumeRolePolicyDocument": { | ||
"Statement": [ | ||
{ | ||
"Action": "sts:AssumeRole", | ||
"Effect": "Allow", | ||
"Principal": { | ||
"Service": "pipes.amazonaws.com", | ||
}, | ||
}, | ||
], | ||
"Version": "2012-10-17", | ||
}, | ||
}, | ||
"Type": "AWS::IAM::Role", | ||
}, | ||
} | ||
`; | ||
|
||
exports[`Kinesis should grant pipe role push access 2`] = ` | ||
{ | ||
"MyPipeRoleDefaultPolicy31387C20": { | ||
"Properties": { | ||
"PolicyDocument": { | ||
"Statement": [ | ||
{ | ||
"Action": [ | ||
"kinesis:ListShards", | ||
"kinesis:PutRecord", | ||
"kinesis:PutRecords", | ||
], | ||
"Effect": "Allow", | ||
"Resource": { | ||
"Fn::GetAtt": [ | ||
"MyStream5C050E93", | ||
"Arn", | ||
], | ||
}, | ||
}, | ||
], | ||
"Version": "2012-10-17", | ||
}, | ||
"PolicyName": "MyPipeRoleDefaultPolicy31387C20", | ||
"Roles": [ | ||
{ | ||
"Ref": "MyPipeRoleCBC8E9AB", | ||
}, | ||
], | ||
}, | ||
"Type": "AWS::IAM::Policy", | ||
}, | ||
} | ||
`; |
Oops, something went wrong.