-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(pipes-sources): add Kinesis and DynamoDB (#29476)
Closes #29378, #29377. ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
- Loading branch information
Showing
37 changed files
with
69,362 additions
and
4 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
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
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 |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import { IPipe, SourceConfig } from '@aws-cdk/aws-pipes-alpha'; | ||
import { ITableV2 } from 'aws-cdk-lib/aws-dynamodb'; | ||
import { IRole } from 'aws-cdk-lib/aws-iam'; | ||
import { DynamoDBStartingPosition } from './enums'; | ||
import { StreamSource, StreamSourceParameters } from './streamSource'; | ||
|
||
/** | ||
* Parameters for the DynamoDB source. | ||
*/ | ||
export interface DynamoDBSourceParameters extends StreamSourceParameters { | ||
/** | ||
* The position in a stream from which to start reading. | ||
* | ||
* @see https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-pipes-pipe-pipesourcedynamodbstreamparameters.html#cfn-pipes-pipe-pipesourcedynamodbstreamparameters-startingposition | ||
*/ | ||
readonly startingPosition: DynamoDBStartingPosition; | ||
} | ||
|
||
/** | ||
* A source that reads from an DynamoDB stream. | ||
*/ | ||
export class DynamoDBSource extends StreamSource { | ||
private readonly table: ITableV2; | ||
private readonly startingPosition: DynamoDBStartingPosition; | ||
private readonly deadLetterTargetArn?: string; | ||
|
||
constructor(table: ITableV2, parameters: DynamoDBSourceParameters) { | ||
if (table.tableStreamArn === undefined) { | ||
throw new Error('Table does not have a stream defined, cannot create pipes source'); | ||
} | ||
|
||
super(table.tableStreamArn, parameters); | ||
this.table = table; | ||
this.startingPosition = parameters.startingPosition; | ||
this.deadLetterTargetArn = this.getDeadLetterTargetArn(this.deadLetterTarget); | ||
} | ||
|
||
bind(_pipe: IPipe): SourceConfig { | ||
return { | ||
sourceParameters: { | ||
dynamoDbStreamParameters: { | ||
batchSize: this.sourceParameters.batchSize, | ||
deadLetterConfig: this.deadLetterTargetArn ? { arn: this.deadLetterTargetArn } : undefined, | ||
maximumBatchingWindowInSeconds: this.sourceParameters.maximumBatchingWindow?.toSeconds(), | ||
maximumRecordAgeInSeconds: this.sourceParameters.maximumRecordAge?.toSeconds(), | ||
maximumRetryAttempts: this.sourceParameters.maximumRetryAttempts, | ||
onPartialBatchItemFailure: this.sourceParameters.onPartialBatchItemFailure, | ||
parallelizationFactor: this.sourceParameters.parallelizationFactor, | ||
startingPosition: this.startingPosition, | ||
}, | ||
}, | ||
}; | ||
} | ||
|
||
grantRead(grantee: IRole): void { | ||
this.table.grantStreamRead(grantee); | ||
} | ||
} |
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,47 @@ | ||
/** | ||
* Define how to handle item process failures. | ||
*/ | ||
export enum OnPartialBatchItemFailure { | ||
/** | ||
* EventBridge halves each batch and will retry each half until all the | ||
* records are processed or there is one failed message left in the batch. | ||
*/ | ||
AUTOMATIC_BISECT = 'AUTOMATIC_BISECT', | ||
} | ||
|
||
/** | ||
* The position in a Kinesis stream from which to start reading. | ||
*/ | ||
export enum KinesisStartingPosition { | ||
/** | ||
* Start streaming at the last untrimmed record in the shard, | ||
* which is the oldest data record in the shard. | ||
*/ | ||
TRIM_HORIZON = 'TRIM_HORIZON', | ||
/** | ||
* Start streaming just after the most recent record in the shard, | ||
* so that you always read the most recent data in the shard. | ||
*/ | ||
LATEST = 'LATEST', | ||
/** | ||
* Start streaming from the position denoted by the time stamp | ||
* specified in the `startingPositionTimestamp` field. | ||
*/ | ||
AT_TIMESTAMP = 'AT_TIMESTAMP', | ||
} | ||
|
||
/** | ||
* The position in a DynamoDB stream from which to start reading. | ||
*/ | ||
export enum DynamoDBStartingPosition { | ||
/** | ||
* Start reading at the last (untrimmed) stream record, | ||
* which is the oldest record in the shard. | ||
*/ | ||
TRIM_HORIZON = 'TRIM_HORIZON', | ||
/** | ||
* Start reading just after the most recent stream record in the shard, | ||
* so that you always read the most recent data in the shard. | ||
*/ | ||
LATEST = 'LATEST', | ||
} |
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 +1,5 @@ | ||
export * from './dynamodb'; | ||
export * from './enums'; | ||
export * from './kinesis'; | ||
export * from './sqs'; | ||
export * from './streamSource'; |
Oops, something went wrong.