-
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: add Step Functions enrichiment for pipes
- Loading branch information
Showing
16 changed files
with
33,699 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 +1,2 @@ | ||
export * from './lambda'; | ||
export * from './stepfunctions'; |
49 changes: 49 additions & 0 deletions
49
packages/@aws-cdk/aws-pipes-enrichments-alpha/lib/stepfunctions.ts
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,49 @@ | ||
import { EnrichmentParametersConfig, IEnrichment, IPipe, InputTransformation } from '@aws-cdk/aws-pipes-alpha'; | ||
import { IRole } from 'aws-cdk-lib/aws-iam'; | ||
import { IStateMachine, StateMachine, StateMachineType } from 'aws-cdk-lib/aws-stepfunctions'; | ||
|
||
/** | ||
* Properties for a StepFunctionsEnrichment | ||
*/ | ||
export interface StepFunctionsEnrichmentProps { | ||
/** | ||
* The input transformation for the enrichment | ||
* @see https://docs.aws.amazon.com/eventbridge/latest/userguide/eb-pipes-input-transformation.html | ||
* @default - None | ||
*/ | ||
readonly inputTransformation?: InputTransformation; | ||
} | ||
|
||
/** | ||
* A StepFunctions enrichment for a pipe | ||
*/ | ||
export class StepFunctionsEnrichment implements IEnrichment { | ||
public readonly enrichmentArn: string; | ||
|
||
private readonly inputTransformation?: InputTransformation; | ||
private readonly stateMachine: IStateMachine; | ||
|
||
constructor(stateMachine: IStateMachine, props?: StepFunctionsEnrichmentProps) { | ||
this.stateMachine=stateMachine; | ||
if (this.stateMachine instanceof StateMachine | ||
&& (this.stateMachine.stateMachineType === StateMachineType.STANDARD) | ||
) { | ||
throw new Error('Enrichiment does not support STANDARD state machine workflows. Use EXPRESS instead.'); | ||
} | ||
this.enrichmentArn = stateMachine.stateMachineArn; | ||
this.inputTransformation = props?.inputTransformation; | ||
} | ||
|
||
bind(pipe: IPipe): EnrichmentParametersConfig { | ||
return { | ||
enrichmentParameters: { | ||
inputTemplate: this.inputTransformation?.bind(pipe).inputTemplate, | ||
}, | ||
}; | ||
} | ||
|
||
grantInvoke(pipeRole: IRole): void { | ||
this.stateMachine.grantStartSyncExecution(pipeRole); | ||
} | ||
} | ||
|
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
76 changes: 76 additions & 0 deletions
76
packages/@aws-cdk/aws-pipes-enrichments-alpha/test/__snapshots__/stepfunctions.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,76 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`stepfunctions should grant pipe role invoke access 1`] = ` | ||
{ | ||
"EnrichmentStateMachineRoleDE810FCA": { | ||
"Properties": { | ||
"AssumeRolePolicyDocument": { | ||
"Statement": [ | ||
{ | ||
"Action": "sts:AssumeRole", | ||
"Effect": "Allow", | ||
"Principal": { | ||
"Service": { | ||
"Fn::FindInMap": [ | ||
"ServiceprincipalMap", | ||
{ | ||
"Ref": "AWS::Region", | ||
}, | ||
"states", | ||
], | ||
}, | ||
}, | ||
}, | ||
], | ||
"Version": "2012-10-17", | ||
}, | ||
}, | ||
"Type": "AWS::IAM::Role", | ||
}, | ||
"MyPipeRoleCBC8E9AB": { | ||
"Properties": { | ||
"AssumeRolePolicyDocument": { | ||
"Statement": [ | ||
{ | ||
"Action": "sts:AssumeRole", | ||
"Effect": "Allow", | ||
"Principal": { | ||
"Service": "pipes.amazonaws.com", | ||
}, | ||
}, | ||
], | ||
"Version": "2012-10-17", | ||
}, | ||
}, | ||
"Type": "AWS::IAM::Role", | ||
}, | ||
} | ||
`; | ||
|
||
exports[`stepfunctions should grant pipe role invoke access 2`] = ` | ||
{ | ||
"MyPipeRoleDefaultPolicy31387C20": { | ||
"Properties": { | ||
"PolicyDocument": { | ||
"Statement": [ | ||
{ | ||
"Action": "states:StartSyncExecution", | ||
"Effect": "Allow", | ||
"Resource": { | ||
"Ref": "EnrichmentStateMachine8BED6C4E", | ||
}, | ||
}, | ||
], | ||
"Version": "2012-10-17", | ||
}, | ||
"PolicyName": "MyPipeRoleDefaultPolicy31387C20", | ||
"Roles": [ | ||
{ | ||
"Ref": "MyPipeRoleCBC8E9AB", | ||
}, | ||
], | ||
}, | ||
"Type": "AWS::IAM::Policy", | ||
}, | ||
} | ||
`; |
Oops, something went wrong.