如何将输入传递给步骤函数映射状态中的任务参数?

How to pass input to the task arguments in step function Map state?

我创建了一个状态机来并行处理 运行 一些 Glue/ETL 作业。我正在试验 Map 状态以利用动态并行性。这是步进函数定义:

{
 "StartAt": "Map",
 "States": {
   "Map": {
     "Type": "Map",
     "InputPath": "$.data",
     "ItemsPath": "$.array",
     "MaxConcurrency": 2,
     "Iterator": {
       "StartAt": "glue job",
       "States": {
         "glue Job": {
           "Type": "Task",
           "Resource": "arn:aws:states:::glue:startJobRun.sync",
           "End": true,
           "Parameters": {
             "JobName": "glue-etl-job",
             "Arguments": {
               "--db": "db-dev",
               "--file": "$.file",
               "--bucket": "$.bucket"
          }
        }
      }
    }
  },
  "Catch": [
    {
      "ErrorEquals": [
        "States.ALL"
      ],
      "Next": "NotifyError"
    }
  ],
  "Next": "NotifySuccess"
},

}
}

传递给step函数的输入格式是这样的:

{
 "data": {
   "array": [
     {"file": "path-to-file1", "bucket": "bucket-name1"},
     {"file": "path-to-file2", "bucket": "bucket-name2"},
   ]
 }
}

问题是 filebucket 作业参数没有得到解决,它们被传递给胶水作业,如 $.file$.bucket。如何从输入传递参数实际值?

使用状态字段作为参数时,需要在参数的'.$'末尾添加。

"--file.$": "$.file",
"--bucket.$": "$.bucket"

如需完整指南,请查看规范 sheet。 https://states-language.net/spec.html#parameters