參考:使用 AWS Batch 的工作案例 EcsProperties - AWS Batch

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

參考:使用 AWS Batch 的工作案例 EcsProperties

為了說明如何根據您的需求EcsProperties建構使用 AWS Batch 的任務定義,本主題會呈現下列RegisterJobDefinition承載。您可以將這些範例複製到檔案中,根據您的需求自訂範例,然後使用 AWS Command Line Interface (AWS CLI) 呼叫 RegisterJobDefinition

AWS Batch Amazon ECS on Amazon 的任務 EC2

以下是 Amazon Elastic Compute Cloud 上的 Amazon Elastic Container Service AWS Batch 任務範例:

{ "jobDefinitionName": "multicontainer-ecs-ec2", "type": "container", "ecsProperties": { "taskProperties": [ { "containers": [ { "name": "c1", "essential": false, "command": [ "echo", "hello world" ], "image": "public.ecr.aws/amazonlinux/amazonlinux:latest", "resourceRequirements": [ { "type": "VCPU", "value": "2" }, { "type": "MEMORY", "value": "4096" } ] }, { "name": "c2", "essential": true, "command": [ "echo", "hello world" ], "image": "public.ecr.aws/amazonlinux/amazonlinux:latest", "resourceRequirements": [ { "type": "VCPU", "value": "6" }, { "type": "MEMORY", "value": "12288" } ] } ] } ] } }

AWS Batch Amazon ECS on Fargate 的任務

以下是 Amazon Elastic Container Service 在 上的 AWS Batch 任務範例 AWS Fargate:

{ "jobDefinitionName": "multicontainer-ecs-fargate", "type": "container", "platformCapabilities": [ "FARGATE" ], "ecsProperties": { "taskProperties": [ { "containers": [ { "name": "c1", "command": [ "echo", "hello world" ], "image": "public.ecr.aws/amazonlinux/amazonlinux:latest", "resourceRequirements": [ { "type": "VCPU", "value": "2" }, { "type": "MEMORY", "value": "4096" } ] }, { "name": "c2", "essential": true, "command": [ "echo", "hello world" ], "image": "public.ecr.aws/amazonlinux/amazonlinux:latest", "resourceRequirements": [ { "type": "VCPU", "value": "6" }, { "type": "MEMORY", "value": "12288" } ] } ], "executionRoleArn": "arn:aws:iam::1112223333:role/ecsTaskExecutionRole" } ] } }

AWS Batch Amazon 的任務 EKS

以下是 Amazon Elastic Kubernetes Service AWS Batch 任務的範例:

{ "jobDefinitionName": "multicontainer-eks", "type": "container", "eksProperties": { "podProperties": { "shareProcessNamespace": true, "initContainers": [ { "name": "init-container", "image": "public.ecr.aws/amazonlinux/amazonlinux:2", "command": [ "echo" ], "args": [ "hello world" ], "resources": { "requests": { "cpu": "1", "memory": "512Mi" } } }, { "name": "init-container-2", "image": "public.ecr.aws/amazonlinux/amazonlinux:2", "command": [ "echo", "my second init container" ], "resources": { "requests": { "cpu": "1", "memory": "512Mi" } } } ], "containers": [ { "name": "c1", "image": "public.ecr.aws/amazonlinux/amazonlinux:2", "command": [ "echo world" ], "resources": { "requests": { "cpu": "1", "memory": "512Mi" } } }, { "name": "sleep-container", "image": "public.ecr.aws/amazonlinux/amazonlinux:2", "command": [ "sleep", "20" ], "resources": { "requests": { "cpu": "1", "memory": "512Mi" } } } ] } } }

MNP AWS Batch 每個節點具有多個容器的任務

以下是每個節點具有多個容器的多節點平行 (MNP) AWS Batch 任務範例:

{ "jobDefinitionName": "multicontainer-mnp", "type": "multinode", "nodeProperties": { "numNodes": 6, "mainNode": 0, "nodeRangeProperties": [ { "targetNodes": "0:5", "ecsProperties": { "taskProperties": [ { "containers": [ { "name": "range05-c1", "command": [ "echo", "hello world" ], "image": "public.ecr.aws/amazonlinux/amazonlinux:latest", "resourceRequirements": [ { "type": "VCPU", "value": "2" }, { "type": "MEMORY", "value": "4096" } ] }, { "name": "range05-c2", "command": [ "echo", "hello world" ], "image": "public.ecr.aws/amazonlinux/amazonlinux:latest", "resourceRequirements": [ { "type": "VCPU", "value": "2" }, { "type": "MEMORY", "value": "4096" } ] } ] } ] } } ] } }