【问题标题】:AWS Step Functions - Pass input to another taskAWS Step Functions - 将输入传递给另一个任务
【发布时间】:2020-02-09 05:48:30
【问题描述】:

如何在 AWS Step Functions 中将输入传递到 task 中的输出?

我知道this question 和文档:

如果 ResultPath 的值为 null,这意味着状态自己的原始输出被丢弃,其原始输入成为它的结果。

但我需要的是:

  • 鉴于我的意见
{
  "input": "my_input"
}
  • 还有我的 lambda 输出
{
  "output": "my_output"
}

我需要将以下 json 传递到下一个状态:

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

【问题讨论】:

    标签: amazon-web-services aws-step-functions


    【解决方案1】:

    我想到了两个建议,Use ResultPath to Replace the Input with the Result,它可以让您

    如果您不指定 ResultPath,则默认行为就像您指定了 "ResultPath": "$"。因为这告诉状态用结果替换整个输入,所以状态输入完全被来自任务结果的结果替换。

    要使此选项起作用,Lambda 函数必须返回所需的响应:

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

    或者在 Step Functions 开发人员指南中使用 Use ResultPath to Include the Result with the Input。接下来,如果您将 Lambda 的返回值更改为仅包含 "my_output",您可以指定 "ResultPath": "$.output" 以实现所需的结果:

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

    【讨论】:

    • 谢谢!实际上,我最终使用了另一个带有 ResultPath 的节点,因为与 lambda 相比,我有更多的空间来处理步骤函数定义。
    【解决方案2】:

    对于任何提出这个问题的人,不可能按照我的要求去做,但你可以做的是,according to the docs

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

    这会将 lambda 返回的任何内容附加到 response 节点中,结果是:

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

    【讨论】:

      猜你喜欢
      • 2018-05-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-17
      • 1970-01-01
      • 2023-04-06
      • 2021-09-04
      • 1970-01-01
      相关资源
      最近更新 更多