Search code examples
amazon-web-servicesaws-step-functions

AWS Step Functions - Pass input to another task


How can I pass my input to my output in a task in AWS Step Functions?

I'm aware of this question, and the docs:

If the value of ResultPath is null, that means that the state’s own raw output is discarded and its raw input becomes its result.

But what I need is:

  • Given my input
{
  "input": "my_input"
}
  • And my lambda output
{
  "output": "my_output"
}

I need to pass to the next state the following json:

{
  "input": "my_input",
  "output": "my_output"
}

Solution

  • Two suggestions comes to mind, either Use ResultPath to Replace the Input with the Result, which allows you to

    If you don't specify a ResultPath, the default behavior is as if you had specified "ResultPath": "$". Because this tells the state to replace the entire input with the result, the state input is completely replaced by the result coming from the task result.

    For this option to work, the Lambda function must return the desired response:

    {
      "input": "my_input",
      "output": "my_output"
    }
    

    Alternatively Use ResultPath to Include the Result with the Input in the Step Functions developer guide. Next, if if you change the return value from you Lambda to include just "my_output" you can specify "ResultPath": "$.output" to achieve the desired result:

    {
      "input": "my_input",
      "output": "my_output"
    }