6

我有一个现有的 AWS Steps 编排,它通过 lambda 执行 AWS Batch 作业。然而,AWS 最近增加了从一个步骤直接调用其他服务(如 AWS Batch)的能力。我很想使用这个新功能,但无法让它发挥作用。

https://docs.aws.amazon.com/step-functions/latest/dg/connectors-batch.html

所以我想用来调用批处理的新步骤操作。

"File Copy": {
  "Type": "Task",
  "Resource": "arn:aws:states:::batch:submitJob.sync",
  "Parameters": {
     "JobName": "MyBatchJob",
     "JobQueue": "MySecondaryQueue",
     "ContainerOverrides.$": "$.lts_job_container_overrides",
     "JobDefinition.$": "$.lts_job_job_definition",
  },
  "Next": "Upload Start"
}

请注意,我正在尝试使用 $. JSONpath 语法,以便动态地通过步骤传递参数。

当给出以下输入时

"lts_job_container_overrides": {
  "environment": [
    {
      "name": "MY_ENV_VARIABLE",
      "value": "XYZ"
    },
  ],
  "command": [
    "/app/file_copy.py"
  ]
},
"lts_job_job_definition": "MyBatchJobDefinition"

我预计环境和命令值将传递给 AWS Batch 中的相应参数 (ContainerOverrides)。相反,AWS Steps 似乎正试图将它们提升为顶级参数 - 然后抱怨它们无效。

{
 "error": "States.Runtime",
 "cause": "An error occurred while executing the state 'File Copy' 
 (entered at the event id #29). The Parameters 
 '{\"ContainerOverrides\":{\"environment\": 
 [{\"name\":\"MY_ENV_VARIALBE\",\"value\":\"XYZ\"}],\"command\": 
 [\"/app/file_copy.py\"]},\"JobDefinition\":\"MyBatchJobDefinition\"}' 
 could not be used to start the Task: [The field 'environment' is not 
 supported by Step Functions, The field 'command' is not supported by 
 Step Functions]"
}

如何阻止 AWS Steps 尝试解释我尝试传递给 AWS Batch 的值?


我已经尝试将 JSON 路径排除在外,只静态指定 ContainerProperties(即使这长期不会成为解决方案)。但即便如此,我也会遇到问题。

"ContainerOverrides": {
   "environment": [
    {
      "name": "RUN_ID",
      "value": "xyz"
    }
   ],
    "command": "/app/file_copy.py"
   }

在这种情况下,步骤本身在加载时拒绝定义文件。

Invalid State Machine Definition: 'SCHEMA_VALIDATION_FAILED: The field 
'environment' is not supported by Step Functions at /States/File 
Copy/Parameters, SCHEMA_VALIDATION_FAILED: The field 'command' is not  
supported by Step Functions at /States/File Copy/Parameters'

所以看起来 ContainerOverrides 是有问题的句号?我是否误解了它在这种情况下的用途?


上述问题已在 AWS Batch 文档中解决(根据以下答案) - AWS 添加了以下注释:

笔记

Step Functions 中的参数以 CamelCase 表示,即使本机服务 API 是 pascalCase。

4

1 回答 1

7

这应该有效,我已经测试过它似乎对我来说工作正常。BothEnvironment和它的对象键 andCommand应该是首字母大写。

{
   "StartAt": "AWS Batch: Manage a job",
   "States": {
      "AWS Batch: Manage a job": {
         "Type": "Task",
         "Resource": "arn:aws:states:::batch:submitJob.sync",
         "Parameters": {
            "JobName": "test",
            "JobDefinition": "jobdef",
            "JobQueue": "testq",
            "ContainerOverrides": {
               "Command": [
                  "/app/file_copy.py"
               ],
               "Environment": [
                  {
                     "Name": "MY_ENV_VARIABLE",
                     "Value": "XYZ"
                  }
               ]            
            }
         },
         "End": true
      }
   }
}
于 2019-01-08T12:20:20.957 回答