-
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-targets): add step function target
Co-authored-by: RaphaelManke <RaphaelManke@users.noreply.github.com>
- Loading branch information
1 parent
205163f
commit 2712ba1
Showing
16 changed files
with
34,071 additions
and
1 deletion.
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 './sqs'; | ||
export * from './stepfunctions'; |
84 changes: 84 additions & 0 deletions
84
packages/@aws-cdk/aws-pipes-targets-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,84 @@ | ||
import { IInputTransformation, IPipe, ITarget, TargetConfig } from '@aws-cdk/aws-pipes-alpha'; | ||
import { IRole } from 'aws-cdk-lib/aws-iam'; | ||
import * as sfn from 'aws-cdk-lib/aws-stepfunctions'; | ||
import { StateMachine, StateMachineType } from 'aws-cdk-lib/aws-stepfunctions'; | ||
|
||
/** | ||
* Parameters for the SfnStateMachine target | ||
*/ | ||
export interface SfnStateMachineParameters { | ||
/** | ||
* 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; | ||
|
||
/** | ||
* Specify whether to invoke the State Machine synchronously (`REQUEST_RESPONSE`) or asynchronously (`FIRE_AND_FORGET`). | ||
* | ||
* @see http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-pipes-pipe-pipetargetsqsqueueparameters.html#cfn-pipes-pipe-pipetargetsqsqueueparameters-messagededuplicationid | ||
* @default StateMachineInvocationType.FIRE_AND_FORGET | ||
*/ | ||
readonly invocationType?: StateMachineInvocationType; | ||
} | ||
|
||
/** | ||
* InvocationType for invoking the State Machine. | ||
* @see https://docs.aws.amazon.com/eventbridge/latest/pipes-reference/API_PipeTargetStateMachineParameters.html | ||
*/ | ||
export enum StateMachineInvocationType { | ||
/** | ||
* Invoke StepFunction asynchronously (`StartExecution`). See https://docs.aws.amazon.com/step-functions/latest/apireference/API_StartExecution.html for more details. | ||
*/ | ||
FIRE_AND_FORGET = 'FIRE_AND_FORGET', | ||
|
||
/** | ||
* Invoke StepFunction synchronously (`StartSyncExecution`) and wait for the execution to complete. See https://docs.aws.amazon.com/step-functions/latest/apireference/API_StartSyncExecution.html for more details. | ||
*/ | ||
REQUEST_RESPONSE = 'REQUEST_RESPONSE', | ||
} | ||
|
||
/** | ||
* An EventBridge Pipes target that sends messages to an AWS Step Functions State Machine. | ||
*/ | ||
export class SfnStateMachine implements ITarget { | ||
public readonly targetArn: string; | ||
|
||
private readonly stateMachine: sfn.IStateMachine; | ||
private readonly invocationType: StateMachineInvocationType; | ||
private readonly inputTemplate?: IInputTransformation; | ||
|
||
constructor(stateMachine: sfn.IStateMachine, parameters: SfnStateMachineParameters) { | ||
this.stateMachine = stateMachine; | ||
this.targetArn = stateMachine.stateMachineArn; | ||
this.invocationType = parameters.invocationType?? StateMachineInvocationType.FIRE_AND_FORGET; | ||
this.inputTemplate = parameters.inputTransformation; | ||
|
||
if (this.stateMachine instanceof StateMachine | ||
&& this.stateMachine.stateMachineType === StateMachineType.STANDARD | ||
&& this.invocationType === StateMachineInvocationType.REQUEST_RESPONSE) { | ||
throw new Error('STANDARD state machine workflows do not support the REQUEST_RESPONSE invocation type. Use FIRE_AND_FORGET instead.'); | ||
} | ||
} | ||
|
||
grantPush(grantee: IRole): void { | ||
if (this.invocationType === StateMachineInvocationType.FIRE_AND_FORGET) { | ||
this.stateMachine.grantStartExecution(grantee); | ||
} else { | ||
this.stateMachine.grantStartSyncExecution(grantee); | ||
} | ||
} | ||
|
||
bind(pipe: IPipe): TargetConfig { | ||
return { | ||
targetParameters: { | ||
inputTemplate: this.inputTemplate?.bind(pipe).inputTemplate, | ||
stepFunctionStateMachineParameters: { | ||
invocationType: this.invocationType, | ||
}, | ||
}, | ||
}; | ||
} | ||
} |
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
142 changes: 142 additions & 0 deletions
142
packages/@aws-cdk/aws-pipes-targets-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,142 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`step-function should grant pipe role push access (StartAsyncExecution) with default invocation type (FIRE_AND_FORGET) 1`] = ` | ||
{ | ||
"MySfnPipeRoleF1D0F697": { | ||
"Properties": { | ||
"AssumeRolePolicyDocument": { | ||
"Statement": [ | ||
{ | ||
"Action": "sts:AssumeRole", | ||
"Effect": "Allow", | ||
"Principal": { | ||
"Service": "pipes.amazonaws.com", | ||
}, | ||
}, | ||
], | ||
"Version": "2012-10-17", | ||
}, | ||
}, | ||
"Type": "AWS::IAM::Role", | ||
}, | ||
"MyStateMachineRoleD59FFEBC": { | ||
"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", | ||
}, | ||
} | ||
`; | ||
|
||
exports[`step-function should grant pipe role push access (StartAsyncExecution) with invocation type FIRE_AND_FORGET 1`] = ` | ||
{ | ||
"MySfnPipeRoleF1D0F697": { | ||
"Properties": { | ||
"AssumeRolePolicyDocument": { | ||
"Statement": [ | ||
{ | ||
"Action": "sts:AssumeRole", | ||
"Effect": "Allow", | ||
"Principal": { | ||
"Service": "pipes.amazonaws.com", | ||
}, | ||
}, | ||
], | ||
"Version": "2012-10-17", | ||
}, | ||
}, | ||
"Type": "AWS::IAM::Role", | ||
}, | ||
"MyStateMachineRoleD59FFEBC": { | ||
"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", | ||
}, | ||
} | ||
`; | ||
|
||
exports[`step-function should grant pipe role push access (StartSyncExecution) with invocation type REQUEST-RESPONSE 1`] = ` | ||
{ | ||
"MySfnPipeRoleF1D0F697": { | ||
"Properties": { | ||
"AssumeRolePolicyDocument": { | ||
"Statement": [ | ||
{ | ||
"Action": "sts:AssumeRole", | ||
"Effect": "Allow", | ||
"Principal": { | ||
"Service": "pipes.amazonaws.com", | ||
}, | ||
}, | ||
], | ||
"Version": "2012-10-17", | ||
}, | ||
}, | ||
"Type": "AWS::IAM::Role", | ||
}, | ||
"MyStateMachineRoleD59FFEBC": { | ||
"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", | ||
}, | ||
} | ||
`; |
Oops, something went wrong.