AWS Step Functions - Pass input to another task

半世苍凉 提交于 2019-12-11 17:30:16

问题


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"
}

回答1:


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"
}



回答2:


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"
  }
}


来源:https://stackoverflow.com/questions/58345667/aws-step-functions-pass-input-to-another-task

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!