What Is AWS Batch? Pricing With Examples, Setup Tutorial, EC2 vs Spot vs Fargate, Array Jobs and Every Stuck in RUNNABLE Fix

Logeshwaran
—

AWS Batch runs your batch jobs, from a few dozen nightly reports to millions of simulations, image renders or data-processing tasks, on containers it starts and stops for you. You package your work as a container image, describe how much CPU, memory and GPU each job needs, and submit jobs to a job queue; Batch launches just enough EC2, EC2 Spot, Fargate or EKS capacity to run them, then scales back to zero. AWS Batch itself is free: you pay only for the compute your jobs use, so a job on Fargate with 1 vCPU and 2 GB for 2 minutes costs you about $0.0016, and 1,000 of them a day about $49 a month. Spot capacity often cuts EC2 costs by 60 to 90 percent for jobs that can be retried. The most common problem is jobs stuck in RUNNABLE, almost always because no compute environment can fit the job, the instances cannot reach ECS, or a quota is full. Below: what Batch is and how it works, compute options and prices with worked examples, a setup tutorial, job definitions, array and multi-node jobs, scheduling, Batch vs Lambda, Step Functions, ECS and Glue, quotas, and every fix for RUNNABLE.

Ethan's client, the online furniture store, wanted 3D-rendered photos of every sofa in every fabric: 40 sofas, 120 fabrics, 4,800 renders, each taking about 6 minutes on a decent machine. On one laptop that was 20 days of rendering. The store's developer had started writing a script to launch EC2 instances, hand them work and shut them down again, and was already on version three. Jake, who had dropped by to fix the showroom tablets, looked at the whiteboard full of arrows and asked: "Isn't there a button for 'run this a few thousand times and tell me when it's done'?" There was. It is called AWS Batch.

⚡ Quick Answer

• What it is: a managed job scheduler that runs your containers on EC2, Spot, Fargate or EKS and scales to zero. Explained.

• Price: Batch is free; you pay for the EC2 or Fargate capacity your jobs use. Worked costs.

• Start: a compute environment, a job queue, a job definition, then submit. Tutorial.

• Stuck in RUNNABLE? Read the job's statusReason: capacity, resource size, network or roles. Every fix.

How it works · EC2 vs Fargate vs Spot · Job definitions · Array jobs · vs Lambda and Step Functions · Quotas · FAQ.

New to containers on AWS? The cards below explain ECS, EC2, Spot and Savings Plans, Fargate pricing and Lambda, the pieces AWS Batch runs on.

🧭 NEW HERE? READ THESE FIRST

These five pages explain the compute AWS Batch runs your jobs on:

📌 Bookmark this; the compute comparison, the worked costs and the RUNNABLE fixes are the parts you will come back for.

What is AWS Batch?

A batch job is work that runs to completion without anyone waiting at a screen: render these images, transcode these videos, process yesterday's files, run this simulation with 10,000 different inputs, retrain this model, generate these PDFs. You usually have many of them, they need more computing power than one machine has, and they do not all need to run right now.

AWS Batch is the managed service that runs those jobs for you. You tell it what to run (a container image and a command), how big each job is (vCPUs, memory, GPUs), and where it may run (a pool of EC2, Spot, Fargate or EKS capacity). Batch keeps a queue of your jobs, decides which job runs next, launches capacity to fit them, places each job on a machine, retries failures, and shuts everything down when the queue is empty. You never manage a scheduler, a cluster or an autoscaling script yourself.

What you would use AWS Batch for:

  • Media: rendering, video transcoding, thumbnails, audio processing.
  • Data processing: nightly file processing, ETL steps in containers, report generation, document conversion.
  • Science and engineering: genomics pipelines, simulations, Monte Carlo risk models, chip design, weather and fluid dynamics, often as array or multi-node jobs.
  • Machine learning: training and batch inference on GPU instances, hyperparameter sweeps, and queueing SageMaker training jobs.
  • Anything a cron job does today that has outgrown one server.

Jake: "So it's a to-do list that hires its own temporary workers and fires them when the list is empty?"

Ethan: "That's the whole service. And it doesn't charge for the to-do list, only for the workers."

How AWS Batch works

AWS Batch has four building blocks, and every job moves through them the same way:

  • Compute environment: a pool of capacity Batch may use, with its type (EC2 On-Demand, EC2 Spot, Fargate, Fargate Spot, or EKS), allowed instance types, minimum and maximum vCPUs, subnets and security groups. A managed compute environment is scaled by Batch; an unmanaged one is capacity you run yourself.
  • Job queue: where you submit jobs. Each queue has a priority and is connected to one to three compute environments, tried in order (for example Spot first, On-Demand as a fallback).
  • Job definition: a template for jobs: the container image, command, vCPUs, memory, GPUs, environment variables, IAM role, retry strategy and timeout.
  • Job: one run of a job definition, submitted to a queue, optionally with overrides, dependencies or as an array of many child jobs.

Here is what happens to each job you submit:

  1. SUBMITTED: you call SubmitJob (from the console, CLI, SDK, EventBridge or Step Functions), and Batch records the job in the queue.
  2. PENDING: the job waits for any jobs it depends on to finish.
  3. RUNNABLE: the job is ready and waiting for capacity. Batch's scheduler picks jobs in order (first in, first out by default, or by fair-share policy) and asks the compute environment for capacity that fits.
  4. STARTING: Batch has placed the job on an instance or a Fargate task, and the container image is being pulled and started.
  5. RUNNING: your container runs. Its output goes to CloudWatch Logs (log group /aws/batch/job by default).
  6. SUCCEEDED or FAILED: the container exited with code 0, or it failed and ran out of retry attempts. Batch keeps the job's details, exit code and status reason for you to inspect.
  7. Scale down: when no RUNNABLE jobs remain, Batch terminates instances it no longer needs, down to the compute environment's minimum vCPUs (zero by default), so your bill stops.
Job stateWhat it meansIf it stays there
SUBMITTEDAccepted into the queueRare; check the queue is ENABLED and VALID
PENDINGWaiting for dependenciesA parent job has not finished, or failed
RUNNABLEReady, waiting for capacitySee stuck in RUNNABLE
STARTINGPlaced; pulling the image and starting the containerImage pull problems (ECR access, NAT, a huge image)
RUNNINGYour container is runningYour code is slow or hung; set a timeout
SUCCEEDED / FAILEDExit code 0, or failed after all attemptsRead the status reason and exit code

Compute options: EC2, Spot, Fargate and EKS

  • EC2 On-Demand: you choose instance families (or "optimal" to let Batch pick from current C, M and R families), and Batch launches instances sized to your queue. You get every instance type, including large-memory and GPU instances, and several jobs can share one instance. Best for big or GPU jobs, and steady workloads you can cover with Savings Plans.
  • EC2 Spot: the same instances at a steep discount, in exchange for AWS reclaiming them with a two-minute warning when it needs the capacity back. Ideal for batch work, because a reclaimed job can simply be retried. Use the SPOT_PRICE_CAPACITY_OPTIMIZED allocation strategy and several instance types so Batch can find spare capacity.
  • Fargate: serverless containers, no instances to choose. Each job gets exactly the vCPU and memory it asks for (up to 16 vCPUs and 120 GB), starts in about a minute and is billed per second. Fargate does not support GPUs or multi-node jobs. Best for small and medium jobs and spiky workloads.
  • Fargate Spot: Fargate at a discount, interruptible like EC2 Spot.
  • Amazon EKS: if your company runs Kubernetes, Batch can schedule jobs as pods on your EKS cluster's nodes, managed by Batch.

Side by side, so you can pick the right compute environment for each queue:

 EC2 On-DemandEC2 SpotFargate / Fargate Spot
You pay forInstances, per secondInstances at the Spot pricevCPU and memory per job, per second (1-minute minimum)
Largest jobLargest instance type you allowSame16 vCPUs, 120 GB
GPUsYesYesNo
Multi-node parallel jobsYesYesNo
Several jobs per machineYes (bin packing)YesNo, one task per job
InterruptionsNoneTwo-minute warning, then reclaimedNone on Fargate; possible on Fargate Spot
Custom AMI, instance storageYes (launch templates)YesNo; up to 200 GB ephemeral storage
Best forBig, GPU or must-finish jobsRetryable bulk work at the lowest priceSmall to medium jobs, no instances to manage

Instance types on EC2: you can list exact types (c6i.xlarge, m7g.2xlarge, g5.xlarge) or whole families (c6i, m7i), or choose optimal and let Batch pick from the C, M and R families. Allowing several families and sizes gives Batch room to pack jobs efficiently and to find Spot capacity; a single exact type is the easiest way to end up with jobs stuck in RUNNABLE.

How Batch scales: each EC2 compute environment has minimum, desired and maximum vCPUs. When jobs are RUNNABLE, Batch raises the desired vCPUs and launches instances to fit them, up to the maximum; when the queue empties, it terminates idle instances after a short while, back down to the minimum. Set the minimum to 0 unless you need instances warm for fast starts, because every minimum vCPU is an instance you pay for around the clock.

Our guide to Reserved Instances vs Savings Plans vs Spot explains which discount fits which workload; for batch jobs, Spot is usually the first answer.

The IAM roles AWS Batch uses, which cause most permission errors when they get mixed up:

  • Service role: lets Batch manage EC2, ECS and Auto Scaling on your behalf. Use the service-linked role AWSServiceRoleForBatch, which the console creates for you, rather than a hand-made role.
  • Instance role (EC2 only): the instance profile your instances run with, usually ecsInstanceRole with the AmazonEC2ContainerServiceforEC2Role policy, so they can join the ECS cluster Batch creates.
  • Execution role: used by the container agent to pull private images from ECR and write logs; required on Fargate.
  • Job role: the permissions your own code gets inside the container, for S3, DynamoDB, Secrets Manager or anything else it calls.

Does AWS Batch use ECS? Yes. For EC2 and Fargate compute environments, Batch creates and manages an Amazon ECS cluster behind the scenes, and each job runs as an ECS task. You see that cluster in the ECS console, but you should let Batch manage it rather than changing it yourself. On EKS compute environments, jobs run as Kubernetes pods instead.

AWS Batch pricing

There is no additional charge for AWS Batch. Job queues, compute environments, job definitions, scheduling policies and the scheduler itself are free. You pay for the resources your jobs run on, at their normal prices, and any discount you already have (Savings Plans, Reserved Instances, Spot) applies automatically:

  • EC2: per-second instance pricing while instances run (for example, in US East, a c6i.xlarge with 4 vCPUs and 8 GiB is $0.17 an hour, a c6i.2xlarge $0.34, a g4dn.xlarge GPU instance $0.526), plus the EBS volumes attached to them.
  • EC2 Spot: the current Spot price for each instance type, often a fraction of On-Demand.
  • Fargate: $0.04048 per vCPU-hour and $0.004445 per GB-hour on Linux x86 in US East ($0.03238 and $0.00356 on Graviton Arm), billed per second with a 1-minute minimum; Fargate Spot is cheaper still.
  • Around the jobs: CloudWatch Logs for your job output, ECR for your images, S3 for your input and output data, and a NAT gateway if your instances reach the internet through one.

Worked examples: what AWS Batch jobs cost

Example 1: small jobs on Fargate. 1,000 jobs a day, each 1 vCPU and 2 GB for 2 minutes:

  • Per job: (1 x $0.04048 + 2 x $0.004445) x 2/60 hour = $0.04937 x 0.0333 = $0.00165
  • Per day: 1,000 x $0.00165 = $1.65; per month about $49.37
  • On Graviton (Arm) Fargate, if your image supports Arm: (0.03238 + 2 x 0.00356) x 0.0333 x 1,000 x 30 = about $39.50 a month.

Example 2: the furniture store's 4,800 renders on EC2. Each render needs 4 vCPUs and about 7 GiB for 6 minutes. On c6i.xlarge instances (one render at a time each):

  • Compute time: 4,800 x 0.1 hour = 480 instance-hours
  • On-Demand: 480 x $0.17 = $81.60, finished in about 2 hours if Batch runs 240 instances at once (960 vCPUs, which needs an EC2 vCPU quota of at least that).
  • On Spot, at a typical 60 to 70 percent discount: roughly $25 to $33, plus a few retries for reclaimed instances.

Ethan: "Twenty days on a laptop, or two hours and about thirty dollars on Spot."

Jake: "And the developer can stop writing version four of his launcher."

Example 3: a nightly report job. One job, 2 vCPUs and 4 GB on Fargate, 15 minutes a night: (2 x 0.04048 + 4 x 0.004445) x 0.25 = $0.0247 a night, about $0.74 a month. Batch is overkill for a single job like this unless it is part of a larger pipeline; an EventBridge-scheduled ECS task or a Lambda function (under 15 minutes) is simpler.

Example 4: GPU batch inference. 200 hours a month of g4dn.xlarge: 200 x $0.526 = $105.20 On-Demand, typically much less on Spot. Batch launches the GPU instances only while jobs are queued, so idle nights cost nothing.

The memory trap that wastes money. On EC2, the ECS agent and the operating system reserve some memory, so an instance with 8 GiB cannot run a job that asks for exactly 8 GiB (8,192 MiB). If your only instance type is c6i.xlarge and your job asks for 8,192 MiB, the job sits in RUNNABLE forever, or Batch jumps to a bigger, pricier instance. Ask for slightly less (for example 7,500 MiB) and check the instance's registered memory in the ECS console.

AWS Batch tutorial: run your first job

The quickest path uses Fargate, so you have no instances to size. You need a container image in Amazon ECR or a public registry; to test, you can use a public image such as public.ecr.aws/amazonlinux/amazonlinux:2023.

  1. Open the AWS Batch console and choose Wizard (or create each part yourself under the navigation pane).
  2. Compute environment: choose Fargate, give it a name, set the maximum vCPUs (for example 256), and pick subnets and a security group. Use private subnets with a NAT gateway or VPC endpoints for ECR, S3 and CloudWatch Logs, or public subnets with Assign public IP turned on, because your jobs must be able to pull images and send logs.
  3. Job queue: create a queue with priority 1 connected to that compute environment.
  4. Job definition: type Fargate, your image, the command (for example echo hello from batch), 1 vCPU, 2 GB of memory, an execution role (lets Fargate pull the image and write logs; the console can create ecsTaskExecutionRole) and, if your code calls AWS services such as S3, a job role with those permissions.
  5. Retry and timeout: set attempts to 2 or 3 and a timeout (the minimum is 60 seconds), so a hung job cannot run up your bill.
  6. Submit a job to your queue. Watch it move from SUBMITTED to RUNNABLE, STARTING, RUNNING and SUCCEEDED, usually within a minute or two on Fargate.
  7. Read the output: open the job, choose the log stream link, and you see your command's output in CloudWatch Logs.

The same from the AWS CLI, once the queue and job definition exist:

# Submit one job
aws batch submit-job --job-name render-test \
  --job-queue render-queue --job-definition render-job:1

# Submit an array job: 4,800 children, each gets AWS_BATCH_JOB_ARRAY_INDEX 0..4799
aws batch submit-job --job-name sofa-renders \
  --job-queue render-queue --job-definition render-job:1 \
  --array-properties size=4800

# Watch progress and find failures
aws batch list-jobs --job-queue render-queue --job-status RUNNABLE
aws batch describe-jobs --jobs a1b2c3d4-5678-90ab-cdef-EXAMPLE11111 \
  --query "jobs[0].[status,statusReason,attempts[-1].container.exitCode]"

And from Python with boto3, which is how most pipelines submit work:

import boto3

batch = boto3.client("batch", region_name="us-east-1")
job = batch.submit_job(
    jobName="nightly-report",
    jobQueue="render-queue",
    jobDefinition="report-job",
    containerOverrides={
        "environment": [{"name": "REPORT_DATE", "value": "2026-10-20"}],
        "resourceRequirements": [{"type": "MEMORY", "value": "4096"}, {"type": "VCPU", "value": "2"}],
    },
    retryStrategy={"attempts": 3},
    timeout={"attemptDurationSeconds": 3600},
)
print(job["jobId"])

Job definitions, retries and timeouts

A job definition is where most of your settings live, and getting it right prevents most failures:

  • Image and command: the container to run and the command to run in it. Use Ref::name placeholders in the command and pass values as parameters when you submit.
  • Resources: vCPUs, memory (in MiB) and GPUs. On EC2, Batch packs several jobs onto one instance when they fit; on Fargate, only certain vCPU and memory combinations are valid (for example 1 vCPU with 2 to 8 GB).
  • Roles: the job role is what your code uses to call AWS (S3, DynamoDB); the execution role lets the agent pull private images and write logs. Mixing them up is a classic AccessDenied.
  • Retry strategy: 1 to 10 attempts. Add evaluateOnExit rules to retry only what can recover, for example retry when the status reason matches Host EC2* (a reclaimed Spot instance) and exit on a real bug's exit code.
  • Timeout: attemptDurationSeconds, at least 60 seconds. Batch stops attempts that run longer, which protects you from a hung job running for days.
  • Logging: the awslogs driver sends output to CloudWatch Logs; you can set your own log group and retention.
  • Storage: EFS volumes for shared files, or more ephemeral storage on Fargate (20 GB included, up to 200 GB).

A retry strategy that survives Spot interruptions without retrying genuine bugs looks like this in the job definition's JSON:

"retryStrategy": {
  "attempts": 5,
  "evaluateOnExit": [
    { "onStatusReason": "Host EC2*", "action": "RETRY" },
    { "onExitCode": "137", "action": "RETRY" },
    { "onReason": "*", "action": "EXIT" }
  ]
}

Exit code 137 usually means the container was killed for using more memory than it asked for; our exit code 137 guide explains it, and the fix is usually more memory in the job definition, not more retries.

Array jobs, dependencies, multi-node jobs and scheduling

  • Array jobs: one submission that creates 2 to 10,000 child jobs. Each child gets an environment variable AWS_BATCH_JOB_ARRAY_INDEX (0, 1, 2 and so on), which your code uses to pick its piece of work, for example line N of a list of files. The furniture store's 4,800 renders were one array job.
  • Dependencies: a job can wait for up to 20 other jobs. For arrays, N_TO_N makes child 5 of job B wait for child 5 of job A, and SEQUENTIAL runs an array's children one after another.
  • Multi-node parallel (MNP) jobs: one job that spans several EC2 instances at once, with one main node and workers that talk to each other, for MPI and distributed training. EC2 only, not Fargate.
  • Fair-share scheduling: by default a queue is first in, first out. A scheduling policy lets several teams or projects share a queue fairly by weight, so one team's 50,000-job array does not starve everyone else.
  • Consumable resources: you can declare limited resources, such as software licenses or database connections, and Batch runs only as many jobs at once as you have of them.
  • Scheduling jobs on a timetable: use EventBridge Scheduler or an EventBridge rule with a cron expression to submit a job every night; our EventBridge cron examples cover the syntax.
  • Pipelines: AWS Step Functions can submit a Batch job and wait for it to finish (the .sync integration), then branch on the result, which is the usual way to chain Batch with Lambda, Glue or SageMaker steps.
  • SageMaker training jobs: Batch can also queue SageMaker training jobs as service jobs, so you can share limited GPU capacity across teams with the same queues and priorities.

Three real AWS Batch designs

  • Process every upload: files land in an S3 bucket; an EventBridge rule on "Object Created" submits a Batch job with the object's key as a parameter; the job converts, resizes or analyzes the file and writes the result to another prefix. When uploads arrive in bulk, a small Lambda function can collect keys and submit one array job instead of thousands of single jobs.
  • Nightly pipeline: EventBridge Scheduler starts a Step Functions state machine at 1 a.m.; the first step runs a Batch array job to process the day's data in parallel, the second runs a single Batch job to merge the results, and the last step sends a report or an alert. If a step fails, Step Functions retries or notifies you, and nothing runs during the day.
  • GPU sweep for machine learning: a data scientist submits an array job where each child trains the same model with different settings on a g5 or g6 Spot instance; the results go to S3, and a final dependent job compares them. Batch launches dozens of GPU instances for an hour and then none, which is the cheapest way to run a sweep you do once a week.

Know when jobs fail. Batch sends a "Batch Job State Change" event to Amazon EventBridge every time a job changes state. A rule that matches "status": ["FAILED"] for your queue and targets an SNS topic emails or messages you the moment a job fails, with its job ID and status reason, so you are not discovering failures from a missing report the next morning. The same events can feed a dashboard of jobs per state.

AWS Batch job stuck in RUNNABLE: every cause and fix

RUNNABLE means the job is ready but Batch cannot place it. Start by reading the job's statusReason (in the console, or aws batch describe-jobs); when Batch can tell why the head of a queue is blocked, it says so there and sends a "job queue blocked" event to EventBridge:

  • MISCONFIGURATION:JOB_RESOURCE_REQUIREMENT: no compute environment on the queue has an instance type big enough for the job's vCPU, memory or GPU request. Allow larger instance types, or ask for less (remember the memory reserved by the ECS agent).
  • MISCONFIGURATION:COMPUTE_ENVIRONMENT_MAX_RESOURCE: the job needs more vCPUs than the compute environment's maxvCpus. Raise maxvCpus.
  • MISCONFIGURATION:EC2_INSTANCE_CONFIGURATION_UNSUPPORTED: the instance types are not available in your chosen subnets' Availability Zones, or your launch template conflicts with them. Pick current-generation types available in those zones.
  • MISCONFIGURATION:SERVICE_ROLE_PERMISSIONS: the Batch service role is missing permissions. Use the AWS Batch service-linked role or the AWSBatchServiceRole managed policy.
  • CAPACITY:INSUFFICIENT_INSTANCE_CAPACITY: EC2 has no capacity for the requested type right now, common with Spot and GPUs. Allow more instance types and Availability Zones, or add an On-Demand compute environment as a fallback.

When there is no statusReason, check these common causes:

  • The instances cannot reach ECS: instances in private subnets need a NAT gateway or VPC endpoints for ECS (and ECR, S3 and CloudWatch Logs for images and logs); instances in public subnets need public IPs. This is the most common cause of all.
  • EC2 quota reached: your account's On-Demand or Spot vCPU quota for that instance family is full. Request an increase in Service Quotas.
  • Custom AMI problems: the ECS agent is not installed, or the awslogs log driver is not enabled (ECS_AVAILABLE_LOGGING_DRIVERS). Use the ECS-optimized AMI unless you have a reason not to.
  • A slow launch template user data script: instances time out before they register with ECS. Keep user data short.
  • The compute environment is INVALID or DISABLED: its status reason explains why (often a deleted subnet, security group or role).
  • The instance role is wrong: EC2 compute environments need an instance profile with the AmazonEC2ContainerServiceforEC2Role policy so instances can join the ECS cluster.

To stop one impossible job from blocking everything behind it, set jobStateTimeLimitActions on the job queue: for the reasons above, Batch can cancel a job that has been RUNNABLE longer than a threshold you choose (for example 10 minutes), and the next job moves up.

Jobs that fail rather than wait: "Essential container in task exited" means your container stopped with an error; read the exit code and the last log lines, as our ECS essential container guide explains. "CannotPullContainerError" means the image could not be pulled: check the image name, the execution role's ECR permissions and the network route to ECR, and see our ECR access guide.

AWS Batch vs Lambda, Step Functions, ECS, Glue and SageMaker

  • Batch vs AWS Lambda: Lambda runs functions for up to 15 minutes with up to 10 GB of memory, starts in milliseconds and suits event-driven work (one file uploaded, one message received). Batch runs containers of any size, for hours or days, with GPUs, queues and priorities. Short and event-driven: Lambda. Long, heavy or thousands at once: Batch.
  • Batch vs ECS: ECS is the container platform; Batch is a job scheduler built on top of it. Run long-lived services (websites, APIs, workers that never stop) on ECS directly. Run finite jobs that queue up, need retries, priorities and automatic scaling to zero, on Batch, which then uses ECS for you.
  • Batch vs Fargate: also not either-or. Fargate is a way to run containers without servers; Batch can use Fargate as its compute. Choose a Fargate compute environment for small and medium jobs, and EC2 or Spot when you need GPUs, very large jobs, multi-node jobs or the lowest price at scale.
  • Batch vs Step Functions: not competitors. Step Functions orchestrates steps and waits; Batch runs the heavy steps. Use them together.
  • Batch vs ECS scheduled tasks: an ECS task on an EventBridge schedule is simpler for one recurring job. Batch adds the queue, retries, priorities, array jobs and automatic capacity, which matter once you have many jobs.
  • Batch vs AWS Glue: Glue is serverless Spark and Python for data integration, with a data catalog. Batch runs any container. For SQL-like data transforms, Glue; for custom code, rendering or science, Batch.
  • Batch vs SageMaker: SageMaker is the managed machine learning platform, with training jobs, batch transform and endpoints. Use SageMaker for ML workflows; use Batch for general compute, or to queue SageMaker training jobs across teams.
  • Batch vs Kubernetes Jobs: if you already run EKS and want Kubernetes-native tools, Batch on EKS gives you Batch's queues and scaling on your cluster; plain Kubernetes Jobs give you less scheduling help.

Looking for "batch inference"? Three different AWS features share the words. Amazon Bedrock batch inference sends a file of prompts to a foundation model and returns the answers later at a discount, with no containers involved; our Bedrock batch inference guide covers it. SageMaker batch transform runs your own trained model over a dataset in S3. AWS Batch runs any inference code you package in a container, on the GPU instances you choose, which suits open models you host yourself and custom pipelines. If you only need a hosted model to answer many prompts, Bedrock's batch inference is the simplest; if you run your own model, Batch or SageMaker.

AWS Batch with the AWS CDK, CloudFormation and Terraform

Most teams define their Batch setup as code, so environments are repeatable. In the AWS CDK, the aws-cdk-lib/aws-batch module has high-level constructs for each piece. A Fargate setup in TypeScript:

import * as batch from "aws-cdk-lib/aws-batch";
import * as ecs from "aws-cdk-lib/aws-ecs";
import { Size } from "aws-cdk-lib";

const ce = new batch.FargateComputeEnvironment(this, "RenderCE", { vpc, maxvCpus: 256 });
const queue = new batch.JobQueue(this, "RenderQueue", {
  computeEnvironments: [{ computeEnvironment: ce, order: 1 }],
});
new batch.EcsJobDefinition(this, "RenderJob", {
  container: new batch.EcsFargateContainerDefinition(this, "RenderContainer", {
    image: ecs.ContainerImage.fromRegistry("public.ecr.aws/amazonlinux/amazonlinux:2023"),
    cpu: 1,
    memory: Size.gibibytes(2),
    command: ["echo", "hello from batch"],
  }),
  retryAttempts: 3,
});

For EC2 and Spot, swap the compute environment for batch.ManagedEc2EcsComputeEnvironment with spot: true, a list of instanceTypes or instanceClasses, and minvCpus: 0, and use batch.EcsEc2ContainerDefinition in the job definition; add the On-Demand environment to the same queue with order: 2 as the fallback. In CloudFormation the resources are AWS::Batch::ComputeEnvironment, AWS::Batch::JobQueue, AWS::Batch::JobDefinition and AWS::Batch::SchedulingPolicy; in Terraform, aws_batch_compute_environment, aws_batch_job_queue and aws_batch_job_definition. One tip whichever tool you use: changing some compute environment settings replaces the environment, so update the job queue to point at the new one in the same deployment, or your jobs will have nowhere to run during the change.

AWS Batch interview questions (with short answers)

  • What are the four main components of AWS Batch? Compute environments, job queues, job definitions and jobs.
  • What does a job in RUNNABLE mean? It is ready to run but has not been placed on capacity yet; check its statusReason, the compute environment's size and network, and quotas.
  • How do you run 10,000 similar tasks? One array job of size 10,000, with each child reading AWS_BATCH_JOB_ARRAY_INDEX.
  • How do you make Spot safe for batch work? Retry strategies with evaluateOnExit on Spot reclaim reasons, several instance types, and an On-Demand fallback environment.
  • When would you choose Fargate over EC2 in Batch? For small to medium jobs without GPUs where you do not want to manage instances; EC2 for GPUs, very large jobs, MNP jobs or the lowest cost at scale.
  • How do you share a queue fairly between teams? A fair-share scheduling policy with share identifiers and weights.
  • Job role vs execution role? The job role is for your code's AWS calls; the execution role is for pulling images and writing logs.
  • How do you chain Batch jobs? Job dependencies (including N_TO_N for arrays), or Step Functions with the .sync integration.

AWS Batch quotas and limits

  • Job queues: 50 per Region. Compute environments: 50 per Region, at most 3 per job queue, and 5 per EKS cluster.
  • Array size: up to 10,000 child jobs per array job.
  • Dependencies: up to 20 per job.
  • Jobs in SUBMITTED state: up to 1,000,000.
  • SubmitJob rate: 50 transactions per second per account; use array jobs instead of submitting thousands of single jobs.
  • Job definition size: 24 KiB; SubmitJob payload: 30 KiB.
  • Retries: 1 to 10 attempts; timeout: at least 60 seconds.

These Batch quotas cannot be raised, but the quotas that usually stop you are the ones underneath: your EC2 vCPU quotas per instance family (On-Demand and Spot), your Fargate vCPU quota, and IP addresses in your subnets. Check them in Service Quotas before a big run.

Best practices and cost controls

  • Use Spot for anything retryable, with several instance types and Availability Zones and the SPOT_PRICE_CAPACITY_OPTIMIZED strategy, and an On-Demand compute environment as a fallback on the same queue.
  • Keep minimum vCPUs at 0 so the environment scales to nothing when idle.
  • Use array jobs for thousands of similar tasks; they are faster to submit and easier to track.
  • Size jobs to fit your instance types, leaving room for the memory the ECS agent reserves.
  • Set timeouts and smart retries on every job definition.
  • Keep images small and close (ECR in the same Region), so STARTING takes seconds, not minutes.
  • Use VPC endpoints for ECR, S3 and CloudWatch Logs to cut NAT gateway data charges on big runs.
  • Tag compute environments by project, and set an AWS Budgets alert; a stuck queue with a high minimum vCPU can quietly run instances all weekend.

Frequently asked questions

What is AWS Batch?

A managed AWS service that runs batch jobs as containers. You submit jobs to a queue, and Batch launches EC2, Spot, Fargate or EKS capacity to run them, retries failures, and scales back to zero when the work is done.

How much does AWS Batch cost?

Nothing extra. You pay only for the compute your jobs run on: EC2 instances (On-Demand or Spot) or Fargate vCPU and memory per second, plus storage, logs and data transfer around them.

Is AWS Batch serverless?

It can be. With Fargate compute environments, there are no instances for you to manage. With EC2 compute environments, Batch manages the instances for you, but they run in your account and you choose their types.

What is a compute environment in AWS Batch?

A pool of capacity Batch may use for your jobs: EC2 On-Demand, EC2 Spot, Fargate, Fargate Spot or EKS, with allowed instance types, minimum and maximum vCPUs, subnets and security groups.

What is a job definition in AWS Batch?

A template for jobs: the container image, command, vCPUs, memory, GPUs, roles, environment variables, retry strategy, timeout and logging settings. Each job you submit uses a job definition, optionally with overrides.

Why is my AWS Batch job stuck in RUNNABLE?

Batch cannot place it. Read the statusReason first: the job may be too big for any allowed instance type, exceed maxvCpus, or hit insufficient capacity. Without a reason, check that instances can reach ECS (NAT or VPC endpoints), EC2 vCPU quotas, the AMI and the instance role.

What is an array job in AWS Batch?

A single submission that creates 2 to 10,000 child jobs, each with its own AWS_BATCH_JOB_ARRAY_INDEX value, so you can process thousands of files or inputs in parallel with one command.

Can AWS Batch use Spot Instances?

Yes, EC2 Spot and Fargate Spot. Batch handles interrupted jobs through your retry strategy, so Spot is a natural fit for batch work and often cuts costs by 60 to 90 percent.

Does AWS Batch support GPUs?

Yes, on EC2 compute environments with GPU instance types such as g4dn, g5, g6 or p-family instances. Specify GPUs in the job definition. Fargate does not support GPUs.

What is the difference between AWS Batch and Lambda?

Lambda runs short, event-driven functions (up to 15 minutes and 10 GB). Batch runs containers of any size and length, with GPUs, queues, priorities and array jobs, which suits heavy and long-running work.

What is the difference between AWS Batch and Step Functions?

Step Functions orchestrates workflows; Batch runs compute jobs. A common design is a Step Functions state machine that submits Batch jobs, waits for them with the .sync integration, and continues based on the result.

How do I schedule an AWS Batch job?

Create an EventBridge Scheduler schedule or an EventBridge rule with a cron or rate expression that targets your job queue and job definition. Batch then submits the job at each scheduled time.

Where are AWS Batch job logs?

In CloudWatch Logs, log group /aws/batch/job by default, with one log stream per job attempt. The job's details page in the console links straight to its log stream.

What is the maximum timeout for an AWS Batch job?

There is no fixed maximum; jobs can run for days. You set a per-attempt timeout with attemptDurationSeconds (at least 60 seconds), and Batch stops attempts that exceed it.

How many times can AWS Batch retry a job?

Between 1 and 10 attempts in the retry strategy. Use evaluateOnExit rules to retry only recoverable failures, such as Spot reclaims, and exit on real errors.

What is a multi-node parallel job?

A job that runs across several EC2 instances at the same time, with a main node and worker nodes that communicate, for MPI workloads and distributed training. It is not available on Fargate.

Can AWS Batch run on Kubernetes?

Yes. AWS Batch on Amazon EKS schedules your jobs as pods on nodes in your EKS cluster, with Batch's queues, priorities and scaling.

Why does my Batch job fail with CannotPullContainerError?

The image could not be pulled: a wrong image name or tag, an execution role without ECR permissions, or no network route to ECR from the subnet (no NAT gateway, public IP or VPC endpoints).

Is AWS Batch free?

The service is. You pay only for the EC2, Spot or Fargate capacity your jobs use, plus storage, logs and data transfer. New AWS accounts can use Free Tier credits or allowances against that compute, as with any EC2 or Fargate usage.

How do I run an AWS Batch job manually?

In the AWS Batch console, choose Jobs, Submit new job, pick the job definition and job queue, adjust any overrides, and submit. From the command line, run aws batch submit-job with the job name, queue and job definition.

What instance types does AWS Batch use?

The ones you allow in the compute environment: specific types, whole families, or optimal, which lets Batch choose from the C, M and R families. Allow several types and sizes so Batch can pack jobs well and find Spot capacity.

How fast does AWS Batch start a job?

On Fargate, usually within a minute or two. On EC2, a few minutes when Batch has to launch a new instance and pull your image, and seconds when a suitable instance is already running. Small images in ECR in the same Region start fastest.

Can one AWS Batch queue run jobs in several Regions?

No. Job queues and compute environments are regional, so a queue only runs jobs in its own Region. For multi-Region work, create the same setup in each Region and submit to the queue where your data lives.

How do I make one stuck job stop blocking my queue?

Cancel it, or set jobStateTimeLimitActions on the job queue so Batch cancels jobs that stay RUNNABLE for a known blocking reason longer than a threshold, letting the next job move to the head of the queue.

For readers preparing for an AWS certification

We have been covering AWS certifications alongside our fixes, so here is a short extra for readers studying for one. If you only came for the fix, you already have it; feel free to skip this part.

Exams that test this topic: Solutions Architect – Associate (SAA-C03) • CloudOps Engineer – Associate (SOA-C03) • Developer – Associate (DVA-C03 from December 1, 2026).

Here are the exam-style questions this topic tends to raise, with the reasoning you need to answer them:

1. A company must run thousands of containerized simulation jobs that need more capacity than one server, scaling to zero when idle, with the least operational effort. Which service fits?

AWS Batch.

2. The same container must process 5,000 different input files in parallel with one submission. What should be used?

An AWS Batch array job, with each child reading AWS_BATCH_JOB_ARRAY_INDEX.

3. How can the cost of fault-tolerant batch jobs be reduced the most?

A Spot compute environment with a retry strategy for Spot reclaims, plus an On-Demand fallback environment on the same queue.

4. AWS Batch jobs stay in RUNNABLE. The instances are in private subnets with no NAT gateway or VPC endpoints. What is the fix?

Give the instances a route to ECS (and ECR, S3, CloudWatch Logs) through a NAT gateway or interface VPC endpoints.

5. A batch job needs GPUs. Which compute environment type must be used?

An EC2 (On-Demand or Spot) compute environment with GPU instance types; Fargate does not support GPUs.

6. A workflow must run a Batch job, wait for it to finish, then call a Lambda function. Which service orchestrates this?

AWS Step Functions, using the Batch .sync integration.

7. The team must be notified as soon as any Batch job fails. What is the simplest design?

An EventBridge rule on Batch Job State Change events with status FAILED, targeting an SNS topic.

Exam codes and dates change often. Our AWS certification changes page keeps track of what is current.

πŸ“š ALSO READ

Where to go next, from Step Functions to container exit codes:

📌 Bookmark this; the compute comparison, the worked costs and the RUNNABLE fixes are the parts you will come back for.

The renders ran on a Saturday morning. The first array job sat in RUNNABLE for twenty minutes because the compute environment allowed only c6i.xlarge and the job asked for exactly 8,192 MiB; Ethan dropped it to 7,500, and within five minutes 240 Spot instances were rendering. All 4,800 images were in S3 by lunchtime, nine renders had been retried after Spot reclaims, and the bill was $31.40. The store's developer deleted his launcher script, and Jake asked whether Batch could also render the coffee tables.

📌 If you keep one line from this page

AWS Batch is a free, managed job queue that runs your containers on EC2, Spot, Fargate or EKS and scales to zero; you pay only for the compute (about $0.0016 for a 2-minute, 1 vCPU Fargate job), and a job stuck in RUNNABLE almost always means it does not fit, cannot reach ECS, or hit a quota.

Spot plus smart retries · leave memory headroom · array jobs for thousands of tasks.

Revision note. Written October 21, 2026. Prices are US East (N. Virginia) list prices on that date. We will update this page when AWS Batch features or the underlying EC2 and Fargate prices change.

Related