使用 Step Functions 執行 AWS Batch 工作負載 - AWS Step Functions

本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。

使用 Step Functions 執行 AWS Batch 工作負載

您可以將 Step Functions 與 整合 AWS Batch ,以在 AWS 雲端中執行批次運算工作負載。此頁面列出支援的 AWS Batch APIs,並提供範例Task狀態來執行批次處理任務。

若要了解如何在 Step Functions 中整合 AWS 服務,請參閱 整合 服務在 Step Functions 中將參數傳遞至服務 API

Optimized AWS Batch Integration 的主要功能

請注意, 請求回應使用任務權杖等待回呼整合模式沒有最佳化。

下列包含提交 AWS Batch 任務並等待任務完成Task的狀態。

{ "StartAt": "BATCH_JOB", "States": { "BATCH_JOB": { "Type": "Task", "Resource": "arn:aws:states:::batch:submitJob.sync", "Parameters": { "JobDefinition": "preprocessing", "JobName": "PreprocessingBatchJob", "JobQueue": "SecondaryQueue", "Parameters.$": "$.batchjob.parameters", "ContainerOverrides": { "ResourceRequirements": [ { "Type": "VCPU", "Value": "4" } ] } }, "End": true } } }

AWS Batch APIs

中的參數Step Functions以 PascalCase 表示

即使原生服務 API 位於 camelCase 中,例如 API 動作 startSyncExecution,您可以在 PascalCase 中指定參數,例如:StateMachineArn

用於呼叫的 IAM 政策 AWS Batch

下列範例範本顯示 如何根據您狀態機器定義中的資源 AWS Step Functions 產生 IAM 政策。如需詳細資訊,請參閱 Step Functions 如何為整合服務產生 IAM 政策探索 Step Functions 中的服務整合模式

由於 AWS Batch 提供資源層級存取控制的部分支援,您必須使用 "Resource": "*"

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:[[region]]:[[accountId]]:rule/StepFunctionsGetEventsForBatchJobsRule" ] } ] }
Request Response
{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "batch:SubmitJob" ], "Resource": "*" } ] }