|
| 1 | +import { EnrichmentParametersConfig, IEnrichment, IPipe, InputTransformation } from '@aws-cdk/aws-pipes-alpha'; |
| 2 | +import { IRole } from 'aws-cdk-lib/aws-iam'; |
| 3 | +import { IStateMachine, StateMachine, StateMachineType } from 'aws-cdk-lib/aws-stepfunctions'; |
| 4 | + |
| 5 | +/** |
| 6 | + * Properties for a StepFunctionsEnrichment |
| 7 | + */ |
| 8 | +export interface StepFunctionsEnrichmentProps { |
| 9 | + /** |
| 10 | + * The input transformation for the enrichment |
| 11 | + * @see https://docs.aws.amazon.com/eventbridge/latest/userguide/eb-pipes-input-transformation.html |
| 12 | + * @default - None |
| 13 | + */ |
| 14 | + readonly inputTransformation?: InputTransformation; |
| 15 | +} |
| 16 | + |
| 17 | +/** |
| 18 | + * A StepFunctions enrichment for a pipe |
| 19 | + */ |
| 20 | +export class StepFunctionsEnrichment implements IEnrichment { |
| 21 | + public readonly enrichmentArn: string; |
| 22 | + |
| 23 | + private readonly inputTransformation?: InputTransformation; |
| 24 | + private readonly stateMachine: IStateMachine; |
| 25 | + |
| 26 | + constructor(stateMachine: IStateMachine, props?: StepFunctionsEnrichmentProps) { |
| 27 | + this.stateMachine=stateMachine; |
| 28 | + if (this.stateMachine instanceof StateMachine |
| 29 | + && (this.stateMachine.stateMachineType === StateMachineType.STANDARD) |
| 30 | + ) { |
| 31 | + throw new Error('Enrichiment does not support STANDARD state machine workflows. Use EXPRESS instead.'); |
| 32 | + } |
| 33 | + this.enrichmentArn = stateMachine.stateMachineArn; |
| 34 | + this.inputTransformation = props?.inputTransformation; |
| 35 | + } |
| 36 | + |
| 37 | + bind(pipe: IPipe): EnrichmentParametersConfig { |
| 38 | + return { |
| 39 | + enrichmentParameters: { |
| 40 | + inputTemplate: this.inputTransformation?.bind(pipe).inputTemplate, |
| 41 | + }, |
| 42 | + }; |
| 43 | + } |
| 44 | + |
| 45 | + grantInvoke(pipeRole: IRole): void { |
| 46 | + this.stateMachine.grantStartSyncExecution(pipeRole); |
| 47 | + } |
| 48 | +} |
| 49 | + |
0 commit comments