将输入参数从一个 Step Function 传递到另一个

Passing Input Parameters from one Step Function to another

我有一个 Step Function A - 它执行 lambda 并提取一些结果。 Same Function 有一个 Map Stage,它迭代结果并且应该从 Map State 调用另一个 Step Function。 从地图状态调用另一个 Step Function B 时,我无法将参数或该记录作为输入传递给 Step Function B。

请建议我如何将输入用于第二步功能。 下面是我正在使用的示例,orderServiceResponse 有一个订单列表,我需要对其进行迭代并将该订单传递给下一步函数。

"Validate-All" : {
       "Type" : "Map",
       "InputPath" : "$.orderServiceResponse",
       "ItemsPath" : "$.orders",
       "MaxConcurrency" : 5,
       "ResultPath" : "$.orders",
        "Iterator" : {
                "StartAt" : "Validate" , 
                "States" :{
                      "Validate" : {
                        "Type" : "Task"
                        "Resource" : "arn:aws:states:::states:startExecution.sync:2",
                        "Parameters" {
                                   "Input" : "$.orders",
                                   "StateMachineArn" : "{arn of Step Function B }
                            },
                          "End" : true
                    }
                 } 

TL;DR 使用 Parameters with Map Context 将完整的输入对象添加到每个 Map 元素迭代中。

您有一组数据要在地图状态中按元素处理。默认情况下,Map 只通过 数组元素的数据到映射迭代器。但是我们可以 add additional context to each iteration.

这是一个例子 - 重要的位被注释掉了:

{
  "StartAt": "MapState",
  "States": {
    "MapState": {
      "Type": "Map",
      "ResultPath": "$.MapResult",
      "Next": "Success",
      // the map's elements of each get the following:
      "Parameters": { 
        "Index.$": "$$.Map.Item.Index", // the array element's data (we only get this by default)
        "Order.$": "$$.Map.Item.Value", // the array element's index 0,1,2...
        "FullInput.$": "$" // a copy of the the full input object <-- this is what you were looking for
      },
      "Catch": [{ "ErrorEquals": ["States.ALL"], "Next": "Fail" }],
      // substitute your iterator:
      "Iterator": {
        "StartAt": "MockTask",
        "States": {
          "MockTask": {
            "End": true,
            "Type": "Task",
            "Resource": "arn:aws:lambda:us-east-1:xxxxxxxxxxxx",
            "Parameters": {
              "expression": "`Order ${$.Order.OrderID} was ordered by ${$.FullInput.CustomerName}`",
              "expressionAttributeValues": {
                "$.Order.OrderID.$": "$.Order.OrderID",
                "$.FullInput.CustomerName.$": "$.FullInput.CustomerName"
              }
            }
          }
        }
      },
      "ItemsPath": "$.Orders"
    },
    "Success": { "Type": "Succeed" },
    "Fail": { "Type": "Fail" }
  }
}

执行输入,3个订单:

{
  "CustomerID": 1,
  "CustomerName": "Morgan Freeman",
  "OtherInfo": { "Foo": "Bar" },
  "Orders": [{ "OrderID": "A", "Status": "Fulfilled" }, { "OrderID": "B", "Status": "Pending" }, { "OrderID": "C", "Status": "Cancelled" }]
}

地图迭代 0 输入:

{
  "Order": { "OrderID": "A", "Status": "Fulfilled" },
  "Index": 0,
  "FullInput": {  "CustomerID": 1, "CustomerName": "Morgan Freeman", "OtherInfo": { "Foo": "Bar" }, "Orders": [{...

执行输出MapResult键

{
  "MapResult": [
    "Order A was ordered by Morgan Freeman",
    "Order B was ordered by Morgan Freeman",
    "Order C was ordered by Morgan Freeman"
  ]
...
}