Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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"
}
like image 427
Gustavo Lopes Avatar asked Oct 11 '19 17:10

Gustavo Lopes


People also ask

How can I pass input to output in AWS step functions?

How can I pass my input to my output in a task in AWS Step Functions? 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. Two suggestions comes to mind, either Use ResultPath to Replace the Input with the Result, which allows you to

How do I design and implement workflows in AWS step functions?

To effectively design and implement workflows in AWS Step Functions, it’s vital to understand the flow of information from one state to another. Still, it’s also crucial to learn how to manipulate and filter this data. In the diagram below, you’ll notice the movement of JSON information throughout a task state:

How do I Pass API parameters to an AWS Batch job?

In case your task state orchestrates an AWS Batch job, you'll easily pass all the relevant API parameters straight to the API actions of that service. The ItemsPath field is utilized in a Map state so you could select an array within the input. A Map state is used to iterate steps for every item within an array found in the input.

What is the States language in AWS step functions?

Understanding how this information flows from state to state, and learning how to filter and manipulate this data, is key to effectively designing and implementing workflows in AWS Step Functions. In the Amazon States Language, these fields filter and control the flow of JSON from state to state:


2 Answers

For anyone who comes to this question, it's not possible to do what I asked, but what you can do is, according to the docs:

{
  "States": {
    "my-state": {
      "Type": "task",
      "ResultPath": "$.response"
    }
  }
}

This will append whatever the lambda returns into the response node, resulting in:

{
  "input": "my_input",
  "response": {
    "output": "my_output"
  }
}
like image 43
Gustavo Lopes Avatar answered Sep 28 '22 11:09

Gustavo Lopes


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"
}
like image 177
matsev Avatar answered Sep 28 '22 10:09

matsev