작업 정의 예제 - AWS Batch

기계 번역으로 제공되는 번역입니다. 제공된 번역과 원본 영어의 내용이 상충하는 경우에는 영어 버전이 우선합니다.

작업 정의 예제

아래 작업 정의 예제는 환경 변수, 파라미터 치환, 볼륨 마운트 등 공통 패턴을 사용하는 방법에 대해서 설명하고 있습니다.

환경 변수 사용

다음은 환경 변수를 사용하여 파일 형식과 Amazon S3 URL을 지정하는 작업 정의 예제입니다. 여기에서 소개하는 예제는 컴퓨팅 블로그 포스트인 Creating a Simple "Fetch & Run" AWS Batch Job에서 가져왔습니다. 이 블로그 포스트에 설명되어 있는 fetch_and_run.sh 스크립트는 환경 변수를 사용하여 myjob.sh 스크립트를 S3에서 다운로드한 후 파일 형식을 선언합니다.

이번 예제에서는 명령 및 환경 변수가 작업 정의로 하드 코딩되어 있지만 명령 및 환경 변수 재정의를 지정하면 더욱 다양한 목적에 맞게 작업 정의를 생성할 수 있습니다.

{ "jobDefinitionName": "fetch_and_run", "type": "container", "containerProperties": { "image": "123456789012.dkr.ecr.us-east-1.amazonaws.com/fetch_and_run", "resourceRequirements": [ { "type": "MEMORY", "value": "2000" }, { "type": "VCPU", "value": "2" } ], "command": [ "myjob.sh", "60" ], "jobRoleArn": "arn:aws:iam::123456789012:role/AWSBatchS3ReadOnly", "environment": [ { "name": "BATCH_FILE_S3_URL", "value": "s3://my-batch-scripts/myjob.sh" }, { "name": "BATCH_FILE_TYPE", "value": "script" } ], "user": "nobody" } }

파라미터 치환 사용

다음은 파라미터 치환을 사용하거나, 기본값을 설정하는 방법을 설명하는 작업 정의 예제입니다.

Ref:: 영역의 command 선언은 파라미터 치환을 위한 자리 표시자를 설정하는 데 사용됩니다. 아래 작업 정의로 작업을 제출할 때는 파라미터 재정의를 지정하여 inputfile이나 outputfile 같은 값을 작성합니다. 아래에서 parameters 섹션은 codec에 대한 기본값을 설정하지만, 필요에 따라 해당 파라미터를 재정의할 수 있습니다.

자세한 내용은 파라미터 섹션을 참조하세요.

{ "jobDefinitionName": "ffmpeg_parameters", "type": "container", "parameters": {"codec": "mp4"}, "containerProperties": { "image": "my_repo/ffmpeg", "resourceRequirements": [ { "type": "MEMORY", "value": "2000" }, { "type": "VCPU", "value": "2" } ], "command": [ "ffmpeg", "-i", "Ref::inputfile", "-c", "Ref::codec", "-o", "Ref::outputfile" ], "jobRoleArn": "arn:aws:iam::123456789012:role/ECSTask-S3FullAccess", "user": "nobody" } }

GPU 기능 테스트

다음 예제의 작업 정의는 GPU 워크로드 AMI 사용에서 설명한 GPU 워크로드 AMI가 제대로 구성되었는지를 테스트합니다. 이 예제 작업 정의에서는 GitHub에서 TensorFlow deep MNIST 분류자 예제를 실행합니다.

{ "containerProperties": { "image": "tensorflow/tensorflow:1.8.0-devel-gpu", "resourceRequirements": [ { "type": "MEMORY", "value": "32000" }, { "type": "VCPU", "value": "8" } ], "command": [ "sh", "-c", "cd /tensorflow/tensorflow/examples/tutorials/mnist; python mnist_deep.py" ] }, "type": "container", "jobDefinitionName": "tensorflow_mnist_deep" }

위의 JSON 텍스트가 포함된 tensorflow_mnist_deep.json이라는 파일을 생성한 후 다음 명령을 사용하여 AWS Batch 작업 정의를 등록할 수 있습니다.

aws batch register-job-definition --cli-input-json file://tensorflow_mnist_deep.json

다중 노드 병렬 작업

다음 작업 정의 예에서는 다중 노드 병렬 작업을 보여 줍니다. 자세한 내용은 AWS 컴퓨팅 블로그의 AWS Batch 내 다중 노드 병렬 작업으로 긴밀하게 결합된 분자 역학 워크플로 구축을 참조하십시오.

{ "jobDefinitionName": "gromacs-jobdef", "jobDefinitionArn": "arn:aws:batch:us-east-2:123456789012:job-definition/gromacs-jobdef:1", "revision": 6, "status": "ACTIVE", "type": "multinode", "parameters": {}, "nodeProperties": { "numNodes": 2, "mainNode": 0, "nodeRangeProperties": [ { "targetNodes": "0:1", "container": { "image": "123456789012.dkr.ecr.us-east-2.amazonaws.com/gromacs_mpi:latest", "resourceRequirements": [ { "type": "MEMORY", "value": "24000" }, { "type": "VCPU", "value": "8" } ], "command": [], "jobRoleArn": "arn:aws:iam::123456789012:role/ecsTaskExecutionRole", "ulimits": [], "instanceType": "p3.2xlarge" } } ] } }