I'm working with AWS CDK to orchestrate Step Functions, and I have a setup where a parent Step Function executes a child Step Function using StepFunctionsStartExecution
. I'm utilizing the IntegrationPattern.WAIT_FOR_TASK_TOKEN
pattern to wait for the child Step Function to complete and return its output back to the parent. I pass a taskToken
to the child Step Function and expect to capture its output for use in subsequent states of the parent Step Function. Here's a simplified version of my CDK TypeScript code:
this.executeChild = new StepFunctionsStartExecution(this, "Execute Step Function", {
stateMachine: childStepFunction.statemachine,
input: TaskInput.fromObject({
key: JsonPath.stringAt("$.data.key"),
bucket: JsonPath.stringAt("$.data.bucket"),
token: JsonPath.taskToken,
}),
resultPath: "$.result",
taskTimeout: Timeout.duration(Duration.minutes(15)),
integrationPattern: IntegrationPattern.WAIT_FOR_TASK_TOKEN,
});
The child Step Function is designed to perform a series of tasks, including interacting with DynamoDB and other AWS services, and then it should signal its completion back to the parent Step Function using the provided taskToken. My goal is to capture the output of the child Step Function directly in the resultPath of the parent Step Function for further processing.
However, I'm unsure how to properly configure both the child and parent Step Functions to ensure that the output of the child is correctly passed back and accessible to the parent Step Function using this taskToken mechanism.
Any advice or examples of configuring the AWS CDK code for this scenario would be greatly appreciated.
Add a Lambda function to the end of the Child Step Function. The Lambda's job is to send back the Child's result to the Parent using the SendTaskSuccess API. SendTaskSuccess
takes two string parameters: output
(the Child's JSON output) and taskToken
(from your input $.token
). You will also want the Child to handle unhappy paths using SendTaskFailure.
The Child's output
will then be available to the Parent's downstream tasks as $.result
, because that's how you've configured the executeChild
task's resultPath
.