在打印窗口把「目标」选为「另存为 PDF」即可保存,页面已带 awsgood.com 版权水印。 返回原文

www.awsgood.com

AWS Batch Pricing: What You Actually Pay Per Job

2026-11-12 AWS Pricing 约 9 分钟

TL;DR

Why your AWS Batch bill has no "Batch" line item

I get asked for "the Batch charge" maybe once a month, and the answer is always the same: there isn't one. Batch is a scheduler. It creates and destroys EC2 instances inside a compute environment you own, and those instances bill at normal On-Demand, Spot, or Savings Plan rates. Fargate compute environments bill per vCPU-second and GB-second with a 1-minute minimum.

So the bill you're chasing lives under EC2-Instances, EC2-Other (EBS), and CloudWatch. If you're hunting a line called "AWSBatch" in Cost Explorer, you'll find nothing and assume something is misconfigured. It isn't.

The reason this matters for unit economics: you cannot optimize what you don't attribute. Turn on cost allocation tags for your compute environments before you do any per-job math, or you'll be dividing the whole account's EC2 spend by your job count and getting nonsense.

# Tag the compute environment at creation so EC2 instances inherit it
aws batch create-compute-environment 
  --compute-environment-name prod-bio-ce 
  --type MANAGED 
  --state ENABLED 
  --compute-resources '{
    "type":"EC2",
    "allocationStrategy":"SPOT_PRICE_CAPACITY_OPTIMIZED",
    "minvCpus":0,
    "maxvCpus":256,
    "instanceTypes":["m5.xlarge","m5.2xlarge","c5.xlarge"],
    "subnets":["subnet-0abc1234"],
    "securityGroupIds":["sg-0def5678"],
    "instanceRole":"arn:aws:iam::111122223333:instance-profile/ecsInstanceRole"
  }' 
  --tags Project=bio-pipeline,CostCenter=research


## Convert the monthly spend into a cost per job

The formula is boring and that's the point:


cost_per_job = (EC2 + EBS + Fargate + logs + NAT) / completed_jobs


Pull `completed_jobs` from CloudWatch. Batch emits `JobsSucceeded`, `JobsFailed`, and `JobsRunning` per job queue. If you've never looked, `JobsFailed` is often 5–15% of `JobsSucceeded` in pipelines with flaky third-party downloads — and those failures still burn instance minutes.

Worked example from a batch rendering pipeline I run in us-east-1, one month:

| Line item | Amount | Notes |
|---|---|---|
| EC2 Spot (m5.2xlarge, ~1,900 instance-hours) | $~610 | spot price floats; treat as approximate |
| EBS gp3 root volumes | $~38 | 50 GB × ~1,900 hours, deleted on scale-in |
| CloudWatch Logs ingestion | $~22 | 14 GB of job stdout |
| NAT Gateway data processed | $~19 | S3 pulls routed through NAT before VPC endpoint existed |
| **Total Batch-attributable** | **~$689** | |
| Jobs succeeded | 41,200 | |
| **Cost per job** | **~$0.0167** | |

Sixteen cents per thousand... no, sixteen-tenths of a cent per job. Compare that to the previous quarter, when the same pipeline ran 38,000 jobs for ~$1,040 — $0.027 per job. Nothing about the jobs changed except the allocation strategy and a 0.5 vCPU reduction on the main container. Same work, 38% cheaper per unit.

That delta is the whole reason to track per-job cost instead of monthly total. A flat monthly number tells you nothing when job volume swings 2× between releases.

## The unit costs hiding inside one job

A single job has a vCPU-second price, a GB-second price, and a fixed per-instance overhead. Splitting them out is what lets you compare two job definitions that look identical on the surface.

Take `m5.xlarge`: 4 vCPU, 16 GiB, roughly $0.192/hour On-Demand in us-east-1 (check current pricing for your region — it moves). That's about $0.048 per vCPU-hour. If your container requests 4 vCPU but pegs at 1.2, you're paying for 2.8 idle vCPUs every second the job runs. On a 40-minute job, that's 112 wasted vCPU-minutes, or roughly 9 cents per job. At 40,000 jobs a month, $3,600 of nothing.

Two measurements worth doing before you touch anything else:

```bash
# 1. What did the job actually ask for?
aws batch describe-job-definitions --job-definitions render-encode:7 
  --query 'jobDefinitions[0].containerProperties.resourceRequirements'

# 2. What did it actually use? CloudWatch Container Insights, or a simple wrapper:
#    print cgroup peaks at the end of the job
cat /sys/fs/cgroup/cpu/cpuacct.usage          # nanoseconds of CPU time
cat /sys/fs/cgroup/memory/memory.max_usage_in_bytes


Divide CPU nanoseconds by wall-clock duration in seconds and you get average vCPUs consumed. I've seen a job request 8 vCPU and average 0.9. That's not a rounding error, that's an 8× overspend on compute.

## Where the money leaks: retries, idle minimums, and log volume

Three leaks account for most overspend I find on audit.

**Retries.** Batch retry strategy defaults to 1 attempt, but people set `attempts: 10` hoping flaky jobs resolve. Each retry re-runs the full container. If a job's real failure mode is a bad input file, you pay 10× for the same crash. Set `evaluateOnExit` with `onReason` matching so only infrastructure failures (`Host EC2*`) retry, and let application errors fail fast.

**`minvCpus` above zero.** Any non-zero minimum keeps instances alive 24/7 whether or not jobs are queued. On a dev queue that's ~$140/month for m5.xlarge sitting at 0% CPU. Set it to 0 on everything except latency-sensitive production queues.

**Log volume.** A chatty job writing 40 MB of stdout per run × 30,000 runs is 1.2 TB/month into CloudWatch Logs. Set a log retention of 7 or 14 days on the `/aws/batch/job` group instead of the default "never expire", and push verbose output to S3.

```bash
aws logs put-retention-policy 
  --log-group-name /aws/batch/job 
  --retention-in-days 14


## Spot, Fargate, or On-Demand: unit cost comparison

The right choice depends on job duration and interruption tolerance more than headline price. Rough shape for a 4 vCPU / 16 GiB job running 40 minutes in us-east-1:

| Option | Basis | Relative cost per job | Good fit |
|---|---|---|---|
| EC2 On-Demand (`m5.xlarge`) | per instance-second, billed hourly | 1.0× (baseline) | short jobs, strict SLAs, <10 min runs |
| EC2 Spot (`SPOT_PRICE_CAPACITY_OPTIMIZED`) | spot market price | ~0.3–0.4× | retryable, checkpointed, 20+ min jobs |
| Fargate | vCPU-s + GB-s, 1-min min | ~1.1–1.4× | bursty, unpredictable shapes, no AMI maintenance |
| Fargate Spot | discounted Fargate | ~0.4–0.6× | batch ETL that tolerates interruptions |

Fargate costs more per hour than Spot EC2 but removes the per-instance fixed overhead, which is exactly what kills you on jobs that run 90 seconds. Spinning up an m5.xlarge for a 90-second task wastes the scale-in/scale-out churn; 200 such jobs an hour is where Fargate wins despite the higher unit rate.

I keep two job queues: a Spot queue for anything over 15 minutes with checkpoints, and a Fargate queue for the short stuff. Routing is by job definition, not by hand.

## When NOT to use this approach

Per-job unit costing is the wrong tool in three situations. If your jobs are heterogeneous by orders of magnitude (a 2-minute lint run and a 6-hour genomics alignment in the same queue), a blended cost-per-job number is meaningless — split by job definition first or you'll optimize the wrong workload.

If you're pre-revenue and running under $200/month total, skip the tagging infrastructure and just watch Cost Explorer weekly; the bookkeeping costs more attention than it saves. And if your jobs are sub-minute and extremely numerous, instance-second granularity plus Batch's own scheduler overhead dominates the math — measure actual EC2 instance-hours instead of deriving from job counts.

## A real failure that cost us two weeks of Spot spend

Late on a Friday in 2026-11 we noticed the Spot queue for an image-transcode pipeline was running 3× the usual instance count while `JobsRunning` sat near zero. CloudWatch showed `JobsFailed` climbing steadily, and the Batch job logs repeated:


CannotPullContainerError: ref pull has been retried 5 time(s):
failed to resolve ref "111122223333.dkr.ecr.us-east-1.amazonaws.com/transcode:v42":
429 Too Many Requests


The first configuration had `maxvCpus: 512` with `SPOT_PRICE_CAPACITY_OPTIMIZED` and `minvCpus: 8`, and every one of those instances was pulling the same 2.1 GB image from ECR at once. ECR throttles pulls per registry per second, so instances came up, failed, got replaced, and failed again — a spin loop that burned instance-hours producing zero finished jobs.

Diagnosis path: I filtered the CloudWatch log group for the error string, saw it clustered within 90-second windows, then checked `ContainerInsights` for image pull duration and confirmed no container ever reached `RUNNING`. The Batch `JobsFailed` metric matched the instance churn exactly.

The fix was three-part: mirror the image through a pull-through cache into a different ECR repo per AZ, set `imagePullSecrets`-free auth via the instance role (it already had it), and reduce `maxvCpus` to 128 so the pull storm couldn't self-amplify. Failure rate went from ~60% to under 1% within an hour, and the next month's Spot spend dropped by roughly the amount the spin loop had been eating. The lesson: retries and fast scale-out multiply each other's costs, and the failure mode looks like a capacity problem until you read the log line.

## Sources

- [AWS Batch pricing](https://aws.amazon.com/batch/pricing/)
- [AWS Batch compute environments](https://docs.aws.amazon.com/batch/latest/userguide/compute_environments.html)
- [Job retry strategies in AWS Batch](https://docs.aws.amazon.com/batch/latest/userguide/job_retries.html)
- [Fargate pricing](https://aws.amazon.com/fargate/pricing/)

## FAQ

Q1: Is AWS Batch free?

A1: The Batch service itself has no charge. You pay only for the resources it launches: EC2 instances or Fargate compute, EBS volumes attached to those instances, CloudWatch Logs, and any data transfer or NAT Gateway processing. A modest pipeline often lands in the tens of dollars per month; the cost scales with job volume.

Q2: How do I calculate the cost per AWS Batch job?

A2: Divide total Batch-attributable spend by completed jobs. Tag compute environments so EC2 costs roll up, pull `JobsSucceeded` from CloudWatch, add EC2 instance-hours, EBS, Fargate vCPU-seconds and log ingestion, then divide. Track it per job definition, since blended numbers hide which workload is expensive.

Q3: Is Spot or Fargate cheaper for AWS Batch?

A3: Spot EC2 is usually cheapest per vCPU-hour but has per-instance startup overhead that hurts jobs under a few minutes. Fargate has a higher unit rate but no fixed instance cost, so it often wins for short, bursty tasks. Use Spot for long checkpointed jobs and Fargate for sub-5-minute work.

Q4: Why is my AWS Batch bill higher than the job count suggests?

A4: Failed and retried jobs still consume compute. A retry strategy of 10 attempts on a deterministic application error multiplies spend by ten with no output. Also check non-zero `minvCpus` keeping idle instances alive, unbounded CloudWatch log retention, and NAT Gateway traffic that a VPC endpoint would avoid.

Q5: Does AWS Batch charge for queued jobs?

A5: No. Jobs waiting in a queue consume no compute and cost nothing. Charges begin when Batch launches an instance or Fargate task and stop when it scales back in — provided your `minvCpus` is 0, since any non-zero minimum keeps instances running around the clock regardless of queue depth.

Q6: How do I stop AWS Batch from overspending on idle instances?

A6: Set `minvCpus: 0` on every compute environment except latency-critical production queues, enable the `optimal` or `SPOT_PRICE_CAPACITY_OPTIMIZED` allocation strategy, and align `maxvCpus` with your real concurrency ceiling. If a queue needs warmth, use a scheduled scaling action rather than a permanent minimum.

Do this today: tag one compute environment, pull `JobsSucceeded` for last month, and divide. If you don't like the number, the fix is almost always in the container's resource requirements — and if you'd rather have someone else watch the `JobsFailed` graphs, that's the sort of thing awsgood.com handles.