AWS Batch
User Guide

Example Job Definitions

The following example job definitions illustrate how to use common patterns such as environment variables, parameter substitution, and volume mounts.

Use Environment Variables

The following example job definition uses environment variables to specify a file type and Amazon S3 URL. This particular example is from the Creating a Simple "Fetch & Run" AWS Batch Job compute blog post. The script that is described in the blog post uses these environment variables to download the script from S3 and declare its file type.

Although the command and environment variables are hard coded into the job definition in this example, you can submit a job with this definition and specify command and environment variable overrides to make the job definition more versatile.

{ "jobDefinitionName": "fetch_and_run", "type": "container", "containerProperties": { "image": "", "vcpus": 2, "memory": 2000, "command": [ "", "60" ], "jobRoleArn": "arn:aws:iam::012345678910:role/AWSBatchS3ReadOnly", "environment": [ { "name": "BATCH_FILE_S3_URL", "value": "s3://my-batch-scripts/" }, { "name": "BATCH_FILE_TYPE", "value": "script" } ], "user": "nobody" } }

Using Parameter Substitution

The following example job definition illustrates how to allow for parameter substitution and to set default values.

The Ref:: declarations in the command section are used to set placeholders for parameter substitution. When you submit a job with this job definition, you specify the parameter overrides to fill in those values, such as the inputfile and outputfile. The parameters section below sets a default for the codec, but you can override that parameter as well if you need to.

For more information, see Parameters.

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

Test GPU Functionality

The following example job definition tests if the GPU workload AMI described in Creating a GPU Workload AMI is configured properly. This example job definition runs the Tensorflow deep MNIST classifier example from GitHub.

{ "containerProperties": { "image": "tensorflow/tensorflow:1.8.0-devel-gpu", "vcpus": 8, "command": [ "sh", "-c", "cd /tensorflow/tensorflow/examples/tutorials/mnist; python" ], "memory": 32000 }, "type": "container", "jobDefinitionName": "tensorflow_mnist_deep" }

You can create a file with the JSON text above called tensorflow_mnist_deep.json and then register an AWS Batch job definition with the following command:

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

The image below shows what the volume and mount points should look like in the AWS Management Console.