无法将数组传递给 AWS StepFunction 中的下一个任务

Cannot pass array to next task in AWS StepFunction

处理从 Lambda 调用获取日期数组的 AWS StepFunction,然后传递给 Task,后者应将该数组作为参数传递给 lambda。

Get Date Range 任务工作正常并输出日期数组:

{
  "rng": [
    "2019-05-07",
    "2019-05-09"
  ]
}

...数组被传递到 ProcessDateRange 任务中,但我无法为数组分配 range 参数。

它从字面上试图传递这个:"$.rng" 而不是这个:

[
    "2019-05-07",
    "2019-05-09"
  ]

这是状态机:

{
  "StartAt": "Try",
  "States": {
    "Try": {
      "Type": "Parallel",
      "Branches": [{
        "StartAt": "Get Date Range",
        "States": {                  
         "Get Date Range": {
            "Type": "Task",
            "Resource": "arn:aws:lambda:us-east-1:123456789:function:get-date-range",
           "Parameters": {
                            "name": "thename",
                            "date_query": "SELECT date from sch.tbl_dates;",
                            "database": "the_db"                          
                        }
          ,     
            "ResultPath": "$.rng",
            "TimeoutSeconds": 900,
            "Next": "ProcessDateRange"            
          },
         "ProcessDateRange": {
            "Type": "Task",
            "Resource": "arn:aws:lambda:us-east-1:123456789:function:process-date-range",
           "Parameters": {                            
                            "range": "$.rng"                            
                        },
           "ResultPath": "$",
            "Next": "Exit"
          },
          "Exit": {
            "Type": "Succeed"
          }
        }
      }],
      "Catch": [{
        "ErrorEquals": ["States.ALL"],
        "ResultPath": "$.Error",
        "Next": "Failed"
      }],
      "Next": "Succeeded"
    },
    "Failed": {
      "Type": "Fail",
      "Cause": "There was an error. Please review the logs.",
      "Error": "error"
    },
    "Succeeded": {
      "Type": "Succeed"
    }
  }
}

这是因为您对 Lambda 任务使用了错误的语法。要指定输入,您需要设置 InputPath 键,例如:

"ProcessDateRange": {
  "Type": "Task",
  "Resource": "arn:aws:lambda:us-east-1:123456789:function:process-date-range",
  "InputPath": "$.rng",
  "ResultPath": "$",
  "Next": "Exit"
},

如果您希望将参数解释为 JSON 路径而不是文字字符串,请在参数名称末尾添加“.$”。要修改您的示例:

"ProcessDateRange": {
    "Type": "Task",
    "Resource": "arn:aws:lambda:us-east-1:123456789:function:process-date-range",
    "Parameters": {                            
        "range.$": "$.rng"                            
    },
    "ResultPath": "$",
    "Next": "Exit"
},

相关文档在这里:https://docs.aws.amazon.com/step-functions/latest/dg/connectors-parameters.html#connectors-parameters-path