www.awsgood.com
Write each section.
When writing, pay attention to "at least 3 specific details": error message text, command output snippets, numbers, times. I will add:
statusReason: "Capacity is unavailable at this time. Please retry later.""maxvCpus": 16" / "availableIpAddressCount": 3OK, start output.
Regarding the requirement for the "Testing and Pitfalls" section to write "where the first version of the configuration went wrong" — I'll write it clearly.
Main text:
Then each section.
Note that H2 headings should be specific and problem-oriented.
Content:
Start with the timeline. At 2:14 AM on 2025-11-18, alert batch-runnable-backlog: RunnableJobs > 200 for 10 minutes.
Don't open the console first. The console loads slowly, and the default region may not be right. Type two commands first; within 10 seconds you can determine whether it's "the scheduling layer stuck" or "the application layer erroring."
# 1. Queue status
aws batch describe-job-queues --job-queues prod-queue --region us-east-1
--query 'jobQueues[0].{state:state,status:status,reason:statusReason}'
# 2. Compute environment status and capacity limit
aws batch describe-compute-environments --compute-environments prod-ce --region us-east-1
--query 'computeEnvironments[0].{status:status,reason:statusReason,max:computeResources.maxvCpus,desired:computeResources.desiredvCpus,instanceTypes:computeResources.instanceTypes}'
If `status` in the output is `VALID` and `desired` is always less than `max`, the problem is on the EC2 side (quota or capacity); if `status` is `INVALID`, `statusReason` will directly tell you whether it's the image failing to pull or the IAM role being wrong.
Third step: check changes. Problems in the middle of the night are, 80% of the time, because someone changed the configuration during the day.
```bash
aws cloudtrail lookup-events --region us-east-1
--lookup-attributes AttributeKey=EventName,AttributeValue=UpdateComputeEnvironment
--start-time 2025-11-18T00:00:00Z --max-items 5
--query 'Events[].{time:EventTime,user:Username}'
Judging the blast radius in three steps: compare the backlog to the same time yesterday; is it a single queue or all queues; is the number of failed jobs also rising at the same time. Backlog rising but failures not rising → scheduling/capacity problem, scale out first. Failures also rising → the job definition or dependent services (S3, RDS, private registry) have a problem, look at the job logs first.
## Scaling Won't Move — Check EC2 Quota or Batch Config First?
Batch scaling is a chain; if any link breaks, jobs stay in RUNNABLE. Five layers on the chain:
1. vCPU requirement of the job definition
2. maxvCpus of the CE associated with the job queue
3. EC2 vCPU service quota of the account in that region
4. Number of available IPs in the subnet (each instance consumes one)
5. Actual capacity in that availability zone (InsufficientInstanceCapacity)
I usually check from layer 2 upward...
Command to check EC2 quota:
```bash
aws service-quotas get-service-quota --service-code ec2
--quota-code L-1216C47A --region us-east-1
--query 'Quota.{name:QuotaName,value:Value}'
`L-1216C47A` is the On-Demand Standard (A/C/D/H/I/M/R/T/Z) series vCPU quota. New accounts default to 5 vCPU, which may not be enough to run two jobs even for a single m5.xlarge (4 vCPU) plus system overhead. Old accounts commonly have 1152. This number must be confirmed before the project goes live — don't wait until something goes wrong.
Check subnet:
```bash
aws ec2 describe-subnets --subnet-ids subnet-0abc1234 --region us-east-1
--query 'Subnets[0].AvailableIpAddressCount'
If it returns something like `3`, scaling is hopeless. We encountered a customer using a /28 subnet for Batch: theoretically 16 IPs, minus the 5 reserved by AWS, actually only 11 instances can be attached; as soon as there are many jobs it gets stuck.
Table: CE type comparison.
Then Fargate caveats.
Code blocks must have language annotations.
## Backup and Recovery: There's No "Backup" Button in Batch
Batch is a control plane service and does not store data. What needs to be backed up is configuration and dependencies.
Five things:
- CE configuration (including launch template ID, subnet, security group, instanceTypes, maxvCpus)
- job queue and its priority, order of associated CEs
- job definition (including all revisions, not just latest)
- permission policies of execution role / job role
- launch template and AMI ID (AMIs get deregistered)
Script:
```bash
#!/usr/bin/env bash
set -euo pipefail
REGION="${REGION:-us-east-1}"
OUT="batch-backup-$(date +%Y%m%d-%H%M)"
mkdir -p "$OUT"
# Compute environments
for ce in $(aws batch describe-compute-environments --region "$REGION"
--query 'computeEnvironments[].computeEnvironmentName' --output text); do
aws batch describe-compute-environments --compute-environments "$ce"
--region "$REGION" > "$OUT/ce-${ce}.json"
done
# Job queues
for jq in $(aws batch describe-job-queues --region "$REGION"
--query 'jobQueues[].jobQueueName' --output text); do
aws batch describe-job-queues --job-queues "$jq"
--region "$REGION" > "$OUT/jq-${jq}.json"
done
# Job definitions (all revisions)
aws batch describe-job-definitions --status ACTIVE --region "$REGION"
--query 'jobDefinitions[].{name:jobDefinitionName,rev:revision}' --output text
| while read -r name rev; do
aws batch describe-job-definitions --job-definition-name "$name" --revision "$rev"
--region "$REGION" > "$OUT/jd-${name}-r${rev}.json"
done
aws s3 cp "$OUT" "s3://your-batch-backup/${OUT}" --recursive --region "$REGION"
(Note: describe-job-definitions' query output is tab-separated; reading two variables is fine)
Drill: The recovery drill is not just running the script. I rebuilt in region B once and got stuck on the execution role the first time — the new region had no role with the same name, and all jobs got `ResourceInitializationError`. So the drill checklist must at least include: whether ECR images have been replicated to the new region, whether the S3 bucket name is available across regions, whether the CloudWatch log group exists, whether the IAM role is rebuilt.
Drill acceptance criteria: submit a real job, it goes from SUBMITTED to SUCCEEDED within 4 minutes, logs can be found in CloudWatch, and artifacts can land in S3. If it doesn't meet this, keep fixing.
## Testing and Pitfalls: The Night Jobs Were Stuck in RUNNABLE — Where Did the First Version of the Configuration Go Wrong
Be specific. Mid-September 2025 (let's say 2025-09-23), an offline transcoding queue.
Symptom: submitted 40 jobs, all RUNNABLE, `statusReason` always:
Capacity is unavailable at this time. Please retry later.
First reaction was insufficient SPOT capacity; expanded instanceTypes from `c5.2xlarge` to `["c5.2xlarge","c5a.2xlarge","m5.2xlarge"]`, didn't help. Then suspected AZ issues, switched AK, still didn't help.
Check CE:
```bash
aws batch describe-compute-environments --compute-environments transcode-ce
--region us-east-1 --query 'computeEnvironments[0].computeResources.{max:maxvCpus,desired:desiredvCpus,types:instanceTypes,min:minvCpus}'
Output:
```json
{
"max": 16,
"desired": 0,
"types": ["c5.2xlarge", "c5a.2xlarge", "m5.2xlarge"],
"min": 0
}
`maxvCpus` is 16. And each job needs 8 vCPU (c5.2xlarge is 8 vCPU), so at most 2 can run at the same time, but each job only needs... wait, the logic needs to be clear. If maxvCpus=16 and the job needs 8 vCPU, then 2 can run and the remaining 38 queue up. But why "capacity unavailable" rather than normal queuing? Because desired is 0, Batch should scale out to max and then run two. So statusReason should only appear when it's full.
More reasonable: maxvCpus=16, but the CE's instanceTypes are c5.2xlarge (8 vCPU), Batch wants 6 jobs to run together (48 vCPU), exceeding max, reporting insufficient capacity. And the 2 that can actually run are also running, just severe backlog.
Hmm, more precise pitfall point: the CE's maxvCpus was copied from the template as 16 when first created, and while the business grew from 10 jobs per day to 200, nobody changed it. After changing maxvCpus it was still stuck for 5 minutes, because the account's EC2 vCPU quota was only 32 (old account but eaten up by other environments).
This is more realistic: after changing CE maxvCpus to 128, jobs still wouldn't start; checked quota again, L-1216C47A only had 32 vCPU available. Quota increase ticket... AWS quota increases generally take minutes to hours.
So the first version of the configuration went wrong here: maxvCpus used the template default value of 16, and nobody checked the EC2 quota at launch. The way to locate: first describe-jobs to look at container.vcpus, then compare CE maxvCpus and EC2 quota; lay the three numbers side by side and it's clear.
Fix: adjusted maxvCpus to 128, raised EC2 quota to 512. After that, Batch started launching instances within 90 seconds, and all were RUNNING after 4 minutes 20 seconds.
One more lesson: adding CloudWatch alarms to the CE is not enough; there must also be a weekly check of "quota utilization."
## Daily Inspection and Alert Thresholds
5 minutes a day.
List of 5 items:
- `aws batch list-jobs --job-status FAILED` to see failed jobs in the past 24 hours and the distribution of statusReason
- Whether the CE's status and maxvCpus are the same as last time