【问题标题】:AWS step functions result manipulationAWS step 函数结果操作
【发布时间】:2021-01-11 23:31:11
【问题描述】:

我有一个 AWS step 函数如下 -

{
  "StartAt": "S1",
  "States": {
    "S1": {
      "Type": "Pass",
      "Parameters": {
        "Fruits.$": "$.Junk.Fruits"
      },
      "ResultPath": "$.Main.Fruits",
      "Next": "S2"
     
    },
    "S2": {
    "Type": "Pass",
    "OutputPath": "$.Main",
    "End": true
  }
  }
}

我的输入如下-

{
    "Main": {
        "Field": "field",
        "Field2": "field2",
        "Fruits":[]
    },
    "Junk": {
        "Fruits":["apple", "banana", "papaya", "grapes"]
    }
}

我得到的输出如下-

{
  "Field": "field",
  "Field2": "field2",
  "Fruits": {
    "Fruits": [
      "apple",
      "banana",
      "papaya",
      "grapes"
    ]
  }
}

我想要的输出如下-

{
    "Field": "field",
    "Field2": "field2",
    "Fruits": [ "apple", "banana", "papaya", "grapes" ]
}

能否请您纠正 step 函数,以便我得到我想要的输出。 请不要使用 lambda 函数,也请不要修改输入。

【问题讨论】:

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


    【解决方案1】:

    您可以像这样使用Parameters 来获得您想要的输出:

    {
      "StartAt": "S1",
      "States": {
        "S1": {
          "Type": "Pass",
          "Parameters": {
            "Field.$": "$.Main.Field",
            "Field2.$": "$.Main.Field2",
            "Fruits.$": "$.Junk.Fruits"
          },
          "End": true
        }
      }
    }
    

    但如果您正在寻找合并两个 JSON 对象(不知道密钥),恐怕 AWS Step Functions 还不支持它。

    【讨论】:

      猜你喜欢
      • 2021-04-26
      • 2018-12-16
      • 1970-01-01
      • 2018-09-19
      • 1970-01-01
      • 1970-01-01
      • 2022-12-12
      • 2017-10-17
      • 1970-01-01
      相关资源
      最近更新 更多