View a markdown version of this page

使用 Step Functions 运行AWS Batch工作负载 - AWS Step Functions

本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。

使用 Step Functions 运行AWS Batch工作负载

您可以将 Step Functions 与集成AWS Batch,以便在AWS云中运行批量计算工作负载。本页列出了支持的,AWS BatchAPIs 并提供了执行批处理任务的示例Task状态。

要了解如何在 Step Functions 中与AWS服务集成,请参阅集成 服务和在 Step Functions 中将参数传递给服务 API。

优化AWS Batch集成的关键特性

请注意,没有针对 请求响应 或 等待具有任务令牌的回调 集成模式的特定优化。

下面显示了一个提交AWS Batch任务并等待其完成的Task状态示例。显示的许多参数都是可选的。

"Submit Batch Job": { "Type": "Task", "Resource": "arn:aws:states:::batch:submitJob.sync", "Arguments": { "JobName": "BATCH_NAME", "JobQueue": "BATCH_QUEUE_ARN", "JobDefinition": "BATCH_JOB_DEFINITION_ARN", "ArrayProperties": { "Size": 10 }, "ContainerOverrides": { "ResourceRequirements": [ { "Type": "VCPU", "Value": "4" } ] }, "DependsOn": [ { "JobId": "myJobId", "Type": "SEQUENTIAL" } ], "PropagateTags": true, "Arguments": { "Key1": "value1", "Key2": 100 }, "RetryStrategy": { "Attempts": 1 }, "Tags": { "Tag": "TAG" }, "Timeout": { "AttemptDurationSeconds": 10 } } }

已优化 AWS BatchAPIs:

中的Step Functions参数表示为 PascalCase

即使原生服务 API 在 camelCase 中(例如 API 操作)startSyncExecution,您也可以在中指定参数 PascalCase,例如:。StateMachineArn

用于呼叫的 IAM 政策 AWS Batch

以下示例模板展示了如何根据状态机定义中的资源AWS Step Functions生成 IAM 策略。有关更多信息,请参阅Step Functions 如何为集成服务生成 IAM 策略和探索 Step Functions 中的服务集成模式。

由于 SubmitJob 和 TerminateJob 的作业 ID 是在运行时生成的(因此只有在运行时才可知),您无法创建基于特定资源来限制访问的策略。

精细访问权限小贴士

要添加对 SubmitJob 和 TerminateJob 的精细访问权限,请考虑对作业使用标签,并创建基于标签限制访问权限的策略。此外,对于 SubmitJob 操作,可以利用已知资源对作业队列、作业定义和可使用资源进行限制。

Run a Job (.sync)
{ "Version":"2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "batch:SubmitJob", "batch:DescribeJobs", "batch:TerminateJob" ], "Resource": "*" }, { "Effect": "Allow", "Action": [ "events:PutTargets", "events:PutRule", "events:DescribeRule" ], "Resource": [ "arn:aws:events:us-east-1:123456789012:rule/StepFunctionsGetEventsForBatchJobsRule" ] } ] }
Request Response
{ "Version":"2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "batch:SubmitJob" ], "Resource": "*" } ] }