本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。
示例数组作业工作流
Amazon Batch 客户的常见工作流程是运行先决条件设置任务,对大量输入任务运行一系列命令,然后完成一项任务,该任务汇总结果并将摘要数据写入 Amazon S3、DynamoDB、Amazon Redshift 或 Aurora。
例如:
-
JobA
:一个标准的非数组任务,它对 Amazon S3 存储桶BucketA
中的对象执行快速列示和元数据验证。SubmitJobJSON 语法如下所示。{ "jobName": "JobA", "jobQueue": "ProdQueue", "jobDefinition": "JobA-list-and-validate:1" }
-
JobB
:一个包含 10000 个副本的数组作业,它依赖于JobA
,针对BucketA
中的每个对象运行 CPU 密集型命令并将结果上传至BucketB
。SubmitJobJSON 语法如下所示。{ "jobName": "JobB", "jobQueue": "ProdQueue", "jobDefinition": "JobB-CPU-Intensive-Processing:1", "containerOverrides": { "resourceRequirements": [ { "type": "MEMORY", "value": "4096" }, { "type": "VCPU", "value": "32" } ] } "arrayProperties": { "size": 10000 }, "dependsOn": [ { "jobId": "
JobA_job_ID
" } ] } -
JobC
:另一个包含 10000 个副本的数组任务,依赖于JobB
,具有N_TO_N
依赖项模型,针对BucketB
中的每个项目运行内存密集型命令,将元数据写入到 DynamoDB,并将生成的输出上传至BucketC
。SubmitJobJSON 语法如下所示。{ "jobName": "JobC", "jobQueue": "ProdQueue", "jobDefinition": "JobC-Memory-Intensive-Processing:1", "containerOverrides": { "resourceRequirements": [ { "type": "MEMORY", "value": "32768" }, { "type": "VCPU", "value": "1" } ] } "arrayProperties": { "size": 10000 }, "dependsOn": [ { "jobId": "
JobB_job_ID
", "type": "N_TO_N" } ] } -
JobD
:一个执行 10 个验证步骤的数组任务,其中每个步骤需要查询 DynamoDB 并且可能与上述任一 Amazon S3 存储桶交互。JobD
中的每个步骤都运行相同的命令。但是,该行为因作业容器内的AWS_BATCH_JOB_ARRAY_INDEX
环境变量的值而异。这些验证步骤按顺序运行 (例如,先运行JobD:0
,再运行JobD:1
,依此类推)。SubmitJobJSON 语法如下所示。{ "jobName": "JobD", "jobQueue": "ProdQueue", "jobDefinition": "JobD-Sequential-Validation:1", "containerOverrides": { "resourceRequirements": [ { "type": "MEMORY", "value": "32768" }, { "type": "VCPU", "value": "1" } ] } "arrayProperties": { "size": 10 }, "dependsOn": [ { "jobId": "
JobC_job_ID
" }, { "type": "SEQUENTIAL" }, ] } -
JobE
:一个最终的非数组任务,它执行一些简单的清除操作并发送包含管道已完成的消息和指向输出 URL 的链接的 Amazon SNS 通知。SubmitJobJSON 语法如下所示。{ "jobName": "JobE", "jobQueue": "ProdQueue", "jobDefinition": "JobE-Cleanup-and-Notification:1", "parameters": { "SourceBucket": "s3://JobD-Output-Bucket", "Recipient": "pipeline-notifications@mycompany.com" }, "dependsOn": [ { "jobId": "
JobD_job_ID
" } ] }