-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(stepfunctions-tasks): cannot specify part of execution data or ta…
…sk context as input to the service integration The Lambda service integration requires an input field called `payload`. We modeled this as a `{[key: string]: any}` which precludes the usage of execution data or context data as inputs to a Lambda function. Fix: Change the type of `payload` to be `TaskInput` which has already modeled a type union for task classes that accept multiple types of payload. This will enable usage of literal strings, objects, execution data, and task context. Rationale: Although this is a breaking change, the workarounds for enabling usage of different types is not user friendly and incomplete as all of the types above cannot be expressed in the current modeling of `payload` Fixes #7371 BREAKING CHANGE: `payload` in RunLambdaTask is now of type `TaskInput`. You can migrate your current assignment to payload by supplying it to the `TaskInput.fromObject()` API
- Loading branch information
Showing
5 changed files
with
277 additions
and
8 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
207 changes: 207 additions & 0 deletions
207
packages/@aws-cdk/aws-stepfunctions-tasks/test/lambda/integ.run-lambda.expected.json
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,207 @@ | ||
{ | ||
"Resources": { | ||
"submitJobLambdaServiceRole4D897ABD": { | ||
"Type": "AWS::IAM::Role", | ||
"Properties": { | ||
"AssumeRolePolicyDocument": { | ||
"Statement": [ | ||
{ | ||
"Action": "sts:AssumeRole", | ||
"Effect": "Allow", | ||
"Principal": { | ||
"Service": "lambda.amazonaws.com" | ||
} | ||
} | ||
], | ||
"Version": "2012-10-17" | ||
}, | ||
"ManagedPolicyArns": [ | ||
{ | ||
"Fn::Join": [ | ||
"", | ||
[ | ||
"arn:", | ||
{ | ||
"Ref": "AWS::Partition" | ||
}, | ||
":iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" | ||
] | ||
] | ||
} | ||
] | ||
} | ||
}, | ||
"submitJobLambdaEFB00F3C": { | ||
"Type": "AWS::Lambda::Function", | ||
"Properties": { | ||
"Code": { | ||
"ZipFile": "exports.handler = async () => {\n return {\n statusCode: '200',\n body: 'hello, world!'\n };\n };" | ||
}, | ||
"Handler": "index.handler", | ||
"Role": { | ||
"Fn::GetAtt": [ | ||
"submitJobLambdaServiceRole4D897ABD", | ||
"Arn" | ||
] | ||
}, | ||
"Runtime": "nodejs10.x" | ||
}, | ||
"DependsOn": [ | ||
"submitJobLambdaServiceRole4D897ABD" | ||
] | ||
}, | ||
"checkJobStateLambdaServiceRoleB8B57B65": { | ||
"Type": "AWS::IAM::Role", | ||
"Properties": { | ||
"AssumeRolePolicyDocument": { | ||
"Statement": [ | ||
{ | ||
"Action": "sts:AssumeRole", | ||
"Effect": "Allow", | ||
"Principal": { | ||
"Service": "lambda.amazonaws.com" | ||
} | ||
} | ||
], | ||
"Version": "2012-10-17" | ||
}, | ||
"ManagedPolicyArns": [ | ||
{ | ||
"Fn::Join": [ | ||
"", | ||
[ | ||
"arn:", | ||
{ | ||
"Ref": "AWS::Partition" | ||
}, | ||
":iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" | ||
] | ||
] | ||
} | ||
] | ||
} | ||
}, | ||
"checkJobStateLambda4618B7B7": { | ||
"Type": "AWS::Lambda::Function", | ||
"Properties": { | ||
"Code": { | ||
"ZipFile": "exports.handler = async function(event, context) {\n return {\n jobState: event.statusCode === 200 ? 'SUCCEEDED' : 'FAILED';\n };\n };" | ||
}, | ||
"Handler": "index.handler", | ||
"Role": { | ||
"Fn::GetAtt": [ | ||
"checkJobStateLambdaServiceRoleB8B57B65", | ||
"Arn" | ||
] | ||
}, | ||
"Runtime": "nodejs10.x" | ||
}, | ||
"DependsOn": [ | ||
"checkJobStateLambdaServiceRoleB8B57B65" | ||
] | ||
}, | ||
"StateMachineRoleB840431D": { | ||
"Type": "AWS::IAM::Role", | ||
"Properties": { | ||
"AssumeRolePolicyDocument": { | ||
"Statement": [ | ||
{ | ||
"Action": "sts:AssumeRole", | ||
"Effect": "Allow", | ||
"Principal": { | ||
"Service": { | ||
"Fn::Join": [ | ||
"", | ||
[ | ||
"states.", | ||
{ | ||
"Ref": "AWS::Region" | ||
}, | ||
".amazonaws.com" | ||
] | ||
] | ||
} | ||
} | ||
} | ||
], | ||
"Version": "2012-10-17" | ||
} | ||
} | ||
}, | ||
"StateMachineRoleDefaultPolicyDF1E6607": { | ||
"Type": "AWS::IAM::Policy", | ||
"Properties": { | ||
"PolicyDocument": { | ||
"Statement": [ | ||
{ | ||
"Action": "lambda:InvokeFunction", | ||
"Effect": "Allow", | ||
"Resource": { | ||
"Fn::GetAtt": [ | ||
"submitJobLambdaEFB00F3C", | ||
"Arn" | ||
] | ||
} | ||
}, | ||
{ | ||
"Action": "lambda:InvokeFunction", | ||
"Effect": "Allow", | ||
"Resource": { | ||
"Fn::GetAtt": [ | ||
"checkJobStateLambda4618B7B7", | ||
"Arn" | ||
] | ||
} | ||
} | ||
], | ||
"Version": "2012-10-17" | ||
}, | ||
"PolicyName": "StateMachineRoleDefaultPolicyDF1E6607", | ||
"Roles": [ | ||
{ | ||
"Ref": "StateMachineRoleB840431D" | ||
} | ||
] | ||
} | ||
}, | ||
"StateMachine2E01A3A5": { | ||
"Type": "AWS::StepFunctions::StateMachine", | ||
"Properties": { | ||
"DefinitionString": { | ||
"Fn::Join": [ | ||
"", | ||
[ | ||
"{\"StartAt\":\"Invoke Handler\",\"States\":{\"Invoke Handler\":{\"Next\":\"Invoke Handler with task token\",\"Parameters\":{\"FunctionName\":\"", | ||
{ | ||
"Ref": "submitJobLambdaEFB00F3C" | ||
}, | ||
"\"},\"Type\":\"Task\",\"Resource\":\"arn:", | ||
{ | ||
"Ref": "AWS::Partition" | ||
}, | ||
":states:::lambda:invoke\"},\"Invoke Handler with task token\":{\"Next\":\"Job Complete?\",\"InputPath\":\"$.Payload\",\"Parameters\":{\"FunctionName\":\"", | ||
{ | ||
"Ref": "checkJobStateLambda4618B7B7" | ||
}, | ||
"\",\"Payload.$\":\"$\"},\"Type\":\"Task\",\"Resource\":\"arn:", | ||
{ | ||
"Ref": "AWS::Partition" | ||
}, | ||
":states:::lambda:invoke\",\"ResultPath\":\"$.status\"},\"Job Complete?\":{\"Type\":\"Choice\",\"Choices\":[{\"Variable\":\"$.status\",\"StringEquals\":\"FAILED\",\"Next\":\"Job Failed\"},{\"Variable\":\"$.status\",\"StringEquals\":\"SUCCEEDED\",\"Next\":\"Final step\"}]},\"Job Failed\":{\"Type\":\"Fail\",\"Error\":\"Received a status that was not 200\",\"Cause\":\"Job Failed\"},\"Final step\":{\"Type\":\"Pass\",\"End\":true}},\"TimeoutSeconds\":30}" | ||
] | ||
] | ||
}, | ||
"RoleArn": { | ||
"Fn::GetAtt": [ | ||
"StateMachineRoleB840431D", | ||
"Arn" | ||
] | ||
} | ||
}, | ||
"DependsOn": [ | ||
"StateMachineRoleDefaultPolicyDF1E6607", | ||
"StateMachineRoleB840431D" | ||
] | ||
} | ||
} | ||
} |
62 changes: 62 additions & 0 deletions
62
packages/@aws-cdk/aws-stepfunctions-tasks/test/lambda/integ.run-lambda.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,62 @@ | ||
import { Code, Function, Runtime } from '@aws-cdk/aws-lambda'; | ||
import * as sfn from '@aws-cdk/aws-stepfunctions'; | ||
import * as cdk from '@aws-cdk/core'; | ||
import * as tasks from '../../lib'; | ||
|
||
const app = new cdk.App(); | ||
const stack = new cdk.Stack(app, 'aws-stepfunctions-tasks-run-lambda-integ'); | ||
|
||
const submitJobLambda = new Function(stack, 'submitJobLambda', { | ||
code: Code.fromInline(`exports.handler = async () => { | ||
return { | ||
statusCode: '200', | ||
body: 'hello, world!' | ||
}; | ||
};`), | ||
runtime: Runtime.NODEJS_10_X, | ||
handler: 'index.handler', | ||
}); | ||
|
||
const submitJob = new sfn.Task(stack, 'Invoke Handler', { | ||
task: new tasks.RunLambdaTask(submitJobLambda), | ||
outputPath: '$.Payload', | ||
}); | ||
|
||
const checkJobStateLambda = new Function(stack, 'checkJobStateLambda', { | ||
code: Code.fromInline(`exports.handler = async function(event, context) { | ||
return { | ||
status: event.statusCode === '200' ? 'SUCCEEDED' : 'FAILED'; | ||
}; | ||
};`), | ||
runtime: Runtime.NODEJS_10_X, | ||
handler: 'index.handler', | ||
}); | ||
|
||
const checkJobState = new sfn.Task(stack, 'Check the job state', { | ||
task: new tasks.RunLambdaTask(checkJobStateLambda, { | ||
payload: sfn.TaskInput.fromDataAt('$.Payload'), | ||
}), | ||
outputPath: '$.Payload' | ||
}); | ||
|
||
const isComplete = new sfn.Choice(stack, 'Job Complete?'); | ||
const jobFailed = new sfn.Fail(stack, 'Job Failed', { | ||
cause: 'Job Failed', | ||
error: 'Received a status that was not 200', | ||
}); | ||
const finalStatus = new sfn.Pass(stack, 'Final step'); | ||
|
||
const chain = sfn.Chain.start(submitJob) | ||
.next(checkJobState) | ||
.next( | ||
isComplete | ||
.when(sfn.Condition.stringEquals('$.status', 'FAILED'), jobFailed) | ||
.when(sfn.Condition.stringEquals('$.status', 'SUCCEEDED'), finalStatus) | ||
); | ||
|
||
new sfn.StateMachine(stack, 'StateMachine', { | ||
definition: chain, | ||
timeout: cdk.Duration.seconds(30), | ||
}); | ||
|
||
app.synth(); |
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