将 AWS 步骤函数任务和映射输出合并到一个数组中

Rya*_*D96 6 amazon-web-services aws-lambda aws-step-functions

我有一个输出以下内容的任务状态:

"batch": {
    "batch": "size",
    "currentTimestamp": 1596205376
  },
Run Code Online (Sandbox Code Playgroud)

映射状态输出输出一个数组:

"batch": [
    {
      "batch": "product-batch-0",
      "currentTimestamp": 1596205376
    },
    {
      "batch": "product-batch-1",
      "currentTimestamp": 1596205376
    }
]
Run Code Online (Sandbox Code Playgroud)

我想将它们组合起来,以便地图状态之后的状态的输入如下:

  "batch": [
    {
    "batch": "Size",
    "currentTimestamp": 1596205376
    },
    {
      "batch": "product-batch-22",
      "currentTimestamp": 1596205376
    },
    {
      "batch": "product-batch-8",
      "currentTimestamp": 1596205376
    }
]
Run Code Online (Sandbox Code Playgroud)

使用 aws 步骤函数中提供的输入/输出处理是否可以实现这一点?我希望将它们包含在一个数组中,以便稍后在状态机中的附加映射状态中一起处理它们。

小智 13

有可能的。尝试这个。

  • 美国手语定义
{
  "StartAt": "getArrayOfArray",
  "States": {
    "getArrayOfArray": {
      "Type": "Pass",
      "Parameters": {
        "arrayOfArray.$": "States.Array($.array, States.Array($.appendant))"
      },
      "Next": "mergeArray"
    },
    "mergeArray": {
      "Type": "Pass",
      "Parameters": {
        "mergedArray.$": "$.arrayOfArray[*][*]"
      },
      "End": true
    }
  }
}
Run Code Online (Sandbox Code Playgroud)
  • 输入
{
  "array": [
    {
      "batch": "product-batch-0",
      "currentTimestamp": 1596205376
    },
    {
      "batch": "product-batch-1",
      "currentTimestamp": 1596205376
    }
  ],
  "appendant": {
    "batch": "size",
    "currentTimestamp": 1596205376
  }
}
Run Code Online (Sandbox Code Playgroud)
  • 输出
{
  "mergedArray": [
    {
      "batch": "product-batch-0",
      "currentTimestamp": 1596205376
    },
    {
      "batch": "product-batch-1",
      "currentTimestamp": 1596205376
    },
    {
      "batch": "size",
      "currentTimestamp": 1596205376
    }
  ]
}
Run Code Online (Sandbox Code Playgroud)


Lam*_*nus 2

您应该使用另一个 Lambda 函数来合并输入和输出,因为步骤函数输出功能无法将结果追加到数组中或将输入和输出合并为数组。

[1]:https://docs.aws.amazon.com/step-functions/latest/dg/input-output-resultpath.html#input-output-resultpath-append