首页 > 解决方案 > 无法将数组传递给 AWS StepFunction 中的下一个任务

问题描述

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

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"
    }
  }
}

标签: amazon-web-servicesaws-lambdaaws-step-functions

解决方案


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

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

推荐阅读