【问题标题】:How to pass parameters to all of the inner workflow tasks inside a Map task?如何将参数传递给 Map 任务中的所有内部工作流任务?
【发布时间】:2021-07-02 02:40:34
【问题描述】:

我正在尝试在状态机中使用 Map 任务。设计很简单——我有一个 lambda 函数,可以生成 Map 状态使用的列表。 Map 任务中的每个任务都应该可以访问列表的属性。

现在我观察到只有第一个任务“ETL”将每个列表元素作为输入,而不是第二个任务“WELL CALC”。

我的 Step Machine 失败了

{
  "error": "States.Runtime",
  "cause": "An error occurred while executing the state 'WELL CALC' (entered at the event id #15). The JSONPath '$.basinName' specified for the field 'basin.$' could not be found in the input '{}'"
}

上述错误为真,ETL lambda 任务的结果返回一个空对象。有没有办法可以将 Map 迭代的“当前项”作为输入传递给所有任务?

这是我的状态机定义:

{
  "StartAt": "Generate Basin List",
  "States": {
    "Generate Basin List": {
      "Type": "Task",
      "Resource": "arn:aws:lambda:us-east-1:451713003466:function:StepFunctionsSample-HelloLam-CheckStockPriceLambda-15TO7SRHAQYQV",
      "Next": "Process Basins"
    },
    "Process Basins": {
      "Type": "Map",
      "ItemsPath": "$.BasinList",
      "End": true,
      "Iterator": {
        "StartAt": "ETL",
        "States": {
          "ETL": {
            "Type": "Task",
            "Resource": "arn:aws:lambda:us-east-1:451713003466:function:StepFunctionsSample-HelloLambda0b4d-BuyStockLambda-1WW8B8JQSZ0SY",
            "Next": "WELL CALC"
          },
          "WELL CALC": {
            "Type": "Task",
            "End": true,
            "Parameters": {
              "basin.$":"$.basinName",
              "phases.$":"$.phases"
            },
            "Resource": "arn:aws:lambda:us-east-1:451713003466:function:StepFunctionsSample-HelloLambda0b4-SellStockLambda-15I8EE3RWDMS5"
          }
        }
      }
    }
  }
}

这是“生成盆地列表”lambda:

exports.lambdaHandler = async (event, context) => {
    return {
        "BasinList": [
            {
                "basinName": "ARDMORE_AND_MARIETTA_BASINS",
                "phases": "1,4,5,8,9,10,13"
            }
        ]
        }
};

【问题讨论】:

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


    【解决方案1】:

    事实证明,我可以将 "ResultPath": null 字段添加到 Map 内的第一个状态 - ETL 这将导致整个输入状态作为输出传递到下一个状态(来源 - https://states-language.net/spec.html#filters):

    ...
    "ETL": {
        "Type": "Task",
        "Resource": "arn:aws:lambda:us..."
        "Next": "WELL CALC",
        "ResultPath": null
    },
    ...
    
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-01-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-04-16
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多