Batch Compute Environment Deployer
An AWS CloudOps agent skill that provisions AWS Batch compute environments, job queues, and job definitions with correct defaults. The skill walks the operator through EC2 vs Fargate vs EKS compute environment selection, launch template integration, allocation strategy decisions, instance types and roles, min/max/desired vCPUs, subnet and security group configuration, job queue creation with priority levels, job definition specification, job dependencies, array jobs, scheduling priority, CloudWatch metrics, and spot instance integration, captures workload and scaling decisions, explains why each default matters, and emits a READY_TO_DEPLOY checklist with copy-pasteable verification commands.
Activation keywords
create Batch compute environment, Batch job queue, register job definition, Batch allocation strategy, Batch spot capacity, Batch Fargate, Batch array jobs, Batch job dependencies.
STRICT output contract
When this skill is invoked with a Batch-provisioning request (create a
compute environment, set up a job queue, register a job definition,
configure spot instances for Batch, use allocation strategies, or set
up array jobs with dependencies), the agent MUST respond with the
READY_TO_DEPLOY checklist defined in the "Output format" section using
the literal all-caps labels BATCH_COMPUTE:, VERDICT:, CHECKLIST:,
and VERIFICATION_COMMANDS:. Do NOT preface the checklist with prose,
headings, or disclaimers — emit the block as the first lines of the
response. This contract is what assertion-based evals and downstream
provisioning pipelines rely on; deviating from the literal labels breaks
automation silently.
If any prerequisite is missing, the verdict is PREREQUISITES_MISSING
with a specific gap citation in the checklist (marked [✗]), and
READY_TO_DEPLOY MUST NOT also appear.
Decision tree leading to the output
1. Is the compute environment type specified?
├─ EC2 → go to 2
├─ Fargate → skip to 3 (no allocation strategy, no launch template)
└─ EKS → go to 2 (also requires EKS cluster ARN)
2. Is the request spot-based?
├─ YES → allocationStrategy MUST be SPOT_CAPACITY_OPTIMIZED
│ type MUST be SPOT; spotIamFleetRole REQUIRED
│ → 3+ instance types for pool diversity
└─ NO → allocationStrategy = BEST_FIT_PROGRESSIVE (≥2 types)
or BEST_FIT (single type, predictable capacity)
3. Is the job queue referencing at least one ENABLED CE?
├─ YES → VERDICT: READY_TO_DEPLOY
└─ NO → VERDICT: PREREQUISITES_MISSING ([✗] State: DISABLED)
4. Does the job definition's vCPU/memory fit the largest instance type?
├─ YES → emit CHECKLIST with [✓] on every line
└─ NO → VERDICT: PREREQUISITES_MISSING ([✗] Job definition: vCPU
request exceeds largest instance type capacity)
5. Emit VERIFICATION_COMMANDS using the actual names from CHECKLIST.
FORBIDDEN output patterns
- NEVER preface the block with prose, greetings, or "Here is your...".
The first line of the response MUST be
BATCH_COMPUTE:. - NEVER emit
VERDICT: READY_TO_DEPLOYwhen any CHECKLIST line is[✗]. A single[✗]forcesVERDICT: PREREQUISITES_MISSING. - NEVER use placeholder text (
<env-name>,your-queue,XXX) in a worked example. Use real names, real ARNs, real instance types. - NEVER omit the
State: ENABLEDline. Creating a CE does NOT enable it; the #1 Batch failure is a DISABLED CE blocking jobs. - NEVER list
SPOT_CAPACITY_OPTIMIZEDfor an On-Demand environment orBEST_FITfor a spot environment. Strategy MUST match type. - NEVER emit a job queue without listing its compute environments and priority. A queue with no ENABLED CE is a silent failure.
- NEVER omit VERIFICATION_COMMANDS. The block is incomplete
without copy-pasteable
aws batch describe-*commands.
Quick navigation
| Section | When to read |
|---|---|
| Prerequisites | Always — verify before provisioning |
| Step 1 — Compute environment type (EC2 vs Fargate vs EKS) | Core model |
| Step 2 — Allocation strategy | Instance selection |
| Step 3 — Launch template integration | Custom AMI / userdata |
| Step 4 — Instance types, role, min/max/desired vCPUs | Capacity |
| Step 5 — Subnet and security group configuration | Networking |
| Step 6 — Job queue creation with priority levels | Queue |
| Step 7 — Job definition (container, vCPU, memory, resources) | Job spec |
| Step 8 — Job dependencies and array jobs | DAG |
| Step 9 — Spot instance integration | Spot capacity |
| Step 10 — CloudWatch metrics and scheduling priority | Observability |
| Step 11 — Recent features | Latest |
| NEVER do these things | Review before signing off |
| Output format | The literal checklist template |
| references/allocation-strategies.md | Allocation strategy detail |
| references/job-definitions-and-queues.md | Job def + queue detail |
Mindset
One-line takeaway: AWS Batch has three layers: compute environment (infrastructure), job queue (priority-ordered routing), and job definition (container + resource spec). A compute environment MUST be ENABLED and a job queue MUST reference it before jobs can run. Allocation strategy is the #1 lever for cost optimization and capacity availability.
Three misconceptions dominate Batch misdesign at provisioning time:
"BEST_FIT is always the right allocation strategy." It is not. BEST_FIT packs jobs tightly onto the fewest instances, which minimizes cost but can cause capacity starvation when instance types are scarce. BEST_FIT_PROGRESSIVE scales out additional instance types when the primary type is unavailable. SPOT_CAPACITY_OPTIMIZED should be used for spot-based compute environments to reduce interruption risk.
"A job queue with one compute environment is enough." Production workloads should have at least two compute environments attached to a job queue: an On-Demand environment (high priority, guaranteed throughput) and a Spot environment (lower priority, cost-efficient burst). The queue priority weighting determines scheduling order.
"Fargate is always cheaper than EC2 for Batch." Fargate charges a per-vCPU and per-GB-memory premium. For sustained workloads, EC2 with BEST_FIT_PROGRESSIVE is typically 40-60% cheaper. Fargate is better for sporadic, short-lived jobs where infra management overhead outweighs the savings.
Configuration dependency graph (novel heuristic)
Batch configurations are NOT independent. The compute environment must be ENABLED before a job queue can reference it. The job queue must exist before jobs can be submitted. The job definition must specify resource requirements satisfiable by the compute environment's instance types.
| Configuration | Hard dependencies (API error without) | Silent failure / immutability | Enables downstream |
|---|---|---|---|
| Service-linked role | none (auto-created on first use) | if deleted, Batch API calls fail | Batch API access |
| Compute environment (EC2) | instance role with ecs trust; subnets; SGs | starts DISABLED — must be ENABLED before jobs run | job queue attachment |
| Compute environment (Fargate) | subnets; security groups | max vCPUs required; no instance role needed | job queue attachment |
| Compute environment (EKS) | EKS cluster exists; EKS compute role | EKS cluster must be same region | job queue attachment |
| Job queue | at least one ENABLED compute environment | priority (1-1000) controls scheduling | job submission |
| Job definition | container image in ECR; vCPU/memory specified | resource requirements must fit instance types | job submission |
| Job dependencies | dependent jobs must exist | SEQUENTIAL waits for ALL children; N-ARY waits for N | DAG scheduling |
| Array jobs | job definition with arrayProperties | array size limit 10000; children are independent | parallel fan-out |
| Spot integration | type MANAGED + SPOT_CAPACITY_OPTIMIZED | spot instances can be interrupted; be idempotent | cost-optimized compute |
| Launch template | EC2 launch template exists | overrides AMI, userdata, EBS settings | custom AMI / userdata |
The compute-environment-must-be-ENABLED row is the one a baseline model misses. Creating a compute environment does NOT enable it. A job queue referencing a DISABLED compute environment will not schedule jobs — they sit in RUNNABLE indefinitely.
Cross-dependency gotchas:
- A job requesting 8 vCPUs cannot run on a compute environment whose largest instance type offers 4 vCPUs — it stays in RUNNABLE forever.
- A job queue tries compute environments in order (1, 2, ...). This is the basis for Spot primary + On-Demand fallback.
- Array children are independent jobs; they may land on different instances and execute in any order.
- Fargate does NOT support launch templates, spot, or allocation strategies — it is always On-Demand.
- EKS compute environments require the Batch service role to have EKS permissions.
Expert heuristic: BEST_FIT_PROGRESSIVE for heterogeneous pools
Moved verbatim to references/allocation-strategies-and-instance-selection.md — load on demand.
Expert heuristic: job dependency DAG and queue priority weighting
Moved verbatim to references/job-definitions-and-dependencies.md — load on demand.
Expert heuristic: spot capacity optimization fallback
Moved verbatim to references/allocation-strategies-and-instance-selection.md — load on demand.
Prerequisites (verify before provisioning)
Before emitting provisioning commands, verify these prerequisites. If any are missing, the verdict is PREREQUISITES_MISSING.
| Prerequisite | Why it matters | How to verify |
|---|---|---|
| Batch service-linked role | Batch needs AWSServiceRoleForBatch | aws iam get-role --role-name AWSServiceRoleForBatch |
| Instance role (EC2) with ECS trust | EC2 instances need ecs:RegisterContainerInstance | aws iam get-role --role-name <instance-role> |
| Subnets identified | Compute environment needs subnet IDs | aws ec2 describe-subnets |
| Security group identified | Instances need a security group | aws ec2 describe-security-groups |
| Container image in ECR | Job definition references an image | aws ecr describe-images --repository-name <repo> |
| Instance types valid for region | Not all types exist in all regions | aws ec2 describe-instance-types |
| EKS cluster exists (if EKS) | EKS environment references a cluster | aws eks describe-cluster --name <cluster> |
| Launch template (if specified) | CE references a launch template | aws ec2 describe-launch-templates |
Step 1 — Compute environment type (EC2 vs Fargate vs EKS)
| Feature | EC2 | Fargate | EKS |
|---|---|---|---|
| Infrastructure | Batch manages EC2 instances | Serverless | Batch manages pods on EKS |
| Instance types | Operator specifies | Abstracted | Operator specifies EKS nodes |
| Allocation strategy | BEST_FIT, BEST_FIT_PROGRESSIVE, SPOT_CAPACITY_OPTIMIZED | N/A (On-Demand) | BEST_FIT, BEST_FIT_PROGRESSIVE |
| Spot support | Yes | No | Yes |
| Launch template | Yes | No | No |
| GPU workloads | Yes (g4dn, p3, p4) | No | Yes |
| Cost (sustained) | Lowest | Highest | Medium |
| Best for | Sustained, GPU, spot | Sporadic, short-lived | Kubernetes-native |
EC2 is most flexible and cost-effective for sustained workloads. Fargate is simplest for sporadic jobs (no spot, no GPUs, no launch templates). EKS consolidates compute for Kubernetes-native shops.
Step 2 — Allocation strategy
| Strategy | Behavior | When to use | Spot |
|---|---|---|---|
| BEST_FIT | Fewest instances; waits if primary type unavailable | Single type, predictable | No |
| BEST_FIT_PROGRESSIVE | Primary first; falls back to other types | Heterogeneous pools, production | No |
| SPOT_CAPACITY_OPTIMIZED | Spot pools with most spare capacity | Spot-based environments | Yes |
BEST_FIT_PROGRESSIVE is the default for EC2 production environments. SPOT_CAPACITY_OPTIMIZED is required for spot-based environments.
Step 3 — Launch template integration
A launch template customizes EC2 instances: custom AMI, user data, EBS volumes, IMDSv2, and more.
# Create a launch template for Batch
aws ec2 create-launch-template \
--launch-template-name batch-custom-lt \
--launch-template-data '{
"ImageId": "ami-0abcdef1234567890",
"BlockDeviceMappings": [{"DeviceName": "/dev/xvda", "Ebs": {"VolumeSize": 100, "VolumeType": "gp3", "Encrypted": true}}],
"MetadataOptions": {"HttpTokens": "required"}
}'
Reference it in the compute environment via launchTemplate: {launchTemplateName: "batch-custom-lt", version: "$Default"}.
Launch templates are only supported for EC2 compute environments.
Step 4 — Instance types, role, min/max/desired vCPUs
| Parameter | Purpose | Recommendation |
|---|---|---|
instanceTypes |
Types Batch can provision | 3+ types for BEST_FIT_PROGRESSIVE |
instanceRole |
IAM instance profile | Must have ecs trust + SSM + CloudWatch |
minvCpus |
Minimum always-provisioned capacity | 0 for cost-optimized; >0 for guaranteed |
maxvCpus |
Maximum capacity cap | Set based on budget |
desiredvCpus |
Initial capacity (Batch auto-adjusts) | Usually 0 |
Critical: the instanceRole must have a trust policy allowing
ecs.amazonaws.com to assume it. Without this, instances cannot
register with the ECS agent and jobs never start.
Step 5 — Subnet and security group configuration
| Parameter | Purpose | Consideration |
|---|---|---|
subnets |
Where Batch provisions instances | Use private subnets; NAT gateway for ECR pulls |
securityGroupIds |
Firewall rules | Allow outbound 443 for ECR + CloudWatch |
Common mistake: specifying only public subnets. Batch instances should be in private subnets with a NAT gateway for outbound traffic. For Fargate, subnets must be in the same VPC.
Step 6 — Job queue creation with priority levels
A job queue routes jobs to one or more compute environments. The priority (1-1000) determines scheduling order when queues compete.
aws batch create-job-queue \
--job-queue-name production-queue \
--state ENABLED \
--priority 500 \
--compute-environment-order \
'[{"order":1,"computeEnvironment":"batch-spot-env"},
{"order":2,"computeEnvironment":"batch-ondemand-env"}]'
Priority semantics: higher = scheduled first. Jobs do NOT preempt running jobs; they get capacity at the next scaling cycle. Two queues with the same priority compete fairly (round-robin).
Compute environment order: Batch tries order 1 first; if at max vCPUs, jobs fall through to order 2. Production pattern: Spot (order 1)
- On-Demand (order 2).
Step 7 — Job definition (container, vCPU, memory, resources)
Moved verbatim to references/job-definitions-and-dependencies.md — load on demand.
Critical resource matching:
- vCPUs and memory must be satisfiable by the compute environment's instance types. A job requesting 8 vCPUs cannot run on 2-vCPU types.
- For Fargate, vCPUs/memory must match supported combinations.
- GPU jobs require GPU instance types (g4dn, p3, p4) and
resourceRequirements: [{"type": "GPU"}].
Step 8 — Job dependencies and array jobs
Sequential dependency:
aws batch submit-job --job-queue production-queue \
--job-definition data-pipeline-v1 --job-name transform-step \
--depends-on '[{"jobId": "ingest-job-id-123"}]'
Array job (fan-out parallelism):
aws batch submit-job --job-queue production-queue \
--job-definition data-pipeline-v1 --job-name parallel-transform \
--array-properties '{"size": 100}'
Each array child gets AWS_BATCH_JOB_ARRAY_INDEX (0 to 99) for work
partitioning. Array size limit: 10000. To depend on array completion,
use {"jobId": "parent-id", "type": "N_TO_N"}.
Step 9 — Spot instance integration
aws batch create-compute-environment \
--compute-environment-name batch-spot-env \
--type MANAGED --state ENABLED \
--compute-resources '{
"type": "SPOT",
"allocationStrategy": "SPOT_CAPACITY_OPTIMIZED",
"minvCpus": 0, "maxvCpus": 1000, "desiredvCpus": 0,
"instanceTypes": ["m5.large", "m5.xlarge", "c5.large", "c5.xlarge", "r5.large"],
"subnets": ["subnet-aaa11122", "subnet-bbb22233"],
"securityGroupIds": ["sg-batch111"],
"instanceRole": "arn:aws:iam::123456789012:instance-profile/batch-instance-profile",
"spotIamFleetRole": "arn:aws:iam::123456789012:role/aws-service-role/spotfleet.amazonaws.com/AWSServiceRoleForEC2SpotFleet"
}' \
--service-role arn:aws:iam::123456789012:role/AWSBatchServiceRole
Requirements: type SPOT, allocation SPOT_CAPACITY_OPTIMIZED,
spotIamFleetRole referencing the EC2 Spot Fleet role. Use 3+ instance
types for pool diversity. Jobs should be idempotent (2-min interruption
warning).
Step 10 — CloudWatch metrics and scheduling priority
| Metric | Measures | Action |
|---|---|---|
CpuUtilization (CPUPct) |
Avg CPU across environment | Scale up if > 80% sustained |
MemoryUtilization (MemoryPct) |
Avg memory | Investigate if > 90% (OOM) |
RUNNABLE count |
Jobs waiting for capacity | Alert if > 0 for > 15 min |
Moved verbatim to references/diagnostic-commands.md — load on demand.
Step 11 — Recent features
Moved verbatim to references/advanced-patterns.md — load on demand.
NEVER do these things
NEVER leave a compute environment in DISABLED state. Creating it does NOT enable it. Jobs to a queue referencing a DISABLED CE sit in RUNNABLE indefinitely. Always verify
state: ENABLED.NEVER use BEST_FIT for heterogeneous instance pools. It waits if the primary type is unavailable. Use BEST_FIT_PROGRESSIVE for pools with 2+ instance types.
NEVER request more vCPUs in a job definition than the compute environment's largest instance type provides. The job will be permanently stuck in RUNNABLE with no error.
NEVER mix allocation strategies incorrectly. Spot requires SPOT_CAPACITY_OPTIMIZED. On-Demand uses BEST_FIT or BEST_FIT_PROGRESSIVE.
NEVER forget the instance role trust policy for EC2. The instance role must allow
ecs.amazonaws.comto assume it. Without this, instances cannot register and jobs never start.NEVER use public subnets for Batch instances. Use private subnets with a NAT gateway. Public subnets expose instances to the internet.
NEVER submit jobs to a queue with zero ENABLED compute environments. The job will sit in RUNNABLE forever.
NEVER assume array children execute in order. Each child is independent and may start/finish in any order. Use
AWS_BATCH_JOB_ARRAY_INDEXto partition work.NEVER use Fargate for GPU workloads. Fargate does not support GPUs. GPU jobs require EC2 with GPU instance types.
NEVER set
maxvCpusarbitrarily high without cost analysis. Batch scales to max if there are RUNNABLE jobs. Set based on budget.
Output format
BATCH_COMPUTE: <compute-environment-name> (<type>, <allocation-strategy>)
VERDICT: READY_TO_DEPLOY | PREREQUISITES_MISSING
CHECKLIST:
[✓|✗] Compute environment type: EC2 | Fargate | EKS
[✓|✗] Compute environment name: <name>
[✓|✗] State: ENABLED | DISABLED
[✓|✗] Allocation strategy: BEST_FIT | BEST_FIT_PROGRESSIVE | SPOT_CAPACITY_OPTIMIZED
[✓|✗] Instance types: <list>
[✓|✗] Instance role: <role-arn> (EC2 only)
[✓|✗] Launch template: <lt-name> (EC2 only) | N/A
[✓|✗] Min vCPUs: <n>, Max vCPUs: <n>, Desired vCPUs: <n>
[✓|✗] Subnets: <list>
[✓|✗] Security groups: <list>
[✓|✗] Spot fleet role: <role-arn> (spot only) | N/A
[✓|✗] Job queue: <queue-name> (priority: <n>, compute environments: <list>)
[✓|✗] Job definition: <name>:<revision> (image: <image>, vCPUs: <n>, memory: <n> MB)
[✓|✗] Job dependencies: none | sequential | N-ary | array (size: <n>)
[✓|✗] CloudWatch metrics: CPUPct, MemoryPct, RUNNABLE count
[✓|✗] Tags: <key=value list>
VERIFICATION_COMMANDS:
aws batch describe-compute-environments --compute-environments <env-name>
aws batch describe-job-queues --job-queues <queue-name>
aws batch describe-job-definitions --job-definition-name <def-name>
Worked example — EC2 with BEST_FIT_PROGRESSIVE
BATCH_COMPUTE: batch-ec2-env (EC2, BEST_FIT_PROGRESSIVE)
VERDICT: READY_TO_DEPLOY
CHECKLIST:
[✓] Compute environment type: EC2
[✓] Compute environment name: batch-ec2-env
[✓] State: ENABLED
[✓] Allocation strategy: BEST_FIT_PROGRESSIVE
[✓] Instance types: m5.large, m5.xlarge, m5.2xlarge
[✓] Instance role: arn:aws:iam::123456789012:instance-profile/batch-instance-profile
[✓] Launch template: batch-custom-lt ($Default)
[✓] Min vCPUs: 0, Max vCPUs: 256, Desired vCPUs: 0
[✓] Subnets: subnet-aaa11122, subnet-bbb22233
[✓] Security groups: sg-batch111
[✓] Spot fleet role: N/A
[✓] Job queue: production-queue (priority: 500, compute environments: batch-ec2-env)
[✓] Job definition: data-pipeline-v1:1 (image: data-pipeline:latest, vCPUs: 4, memory: 8192 MB)
[✓] Job dependencies: none
[✓] CloudWatch metrics: CPUPct, MemoryPct, RUNNABLE count
[✓] Tags: Environment=production, Workload=data-pipeline
VERIFICATION_COMMANDS:
aws batch describe-compute-environments --compute-environments batch-ec2-env
aws batch describe-job-queues --job-queues production-queue
aws batch describe-job-definitions --job-definition-name data-pipeline-v1
Worked example — Spot CE with SPOT_CAPACITY_OPTIMIZED + On-Demand fallback
Moved verbatim to references/worked-examples.md — load on demand.
Error handling
Moved verbatim to references/error-handling.md — load on demand.
References (load on demand)
- references/worked-examples.md — secondary worked examples
- references/error-handling.md — error-handling deep dives (RUNNABLE stuck, INVALID CE, spot interruption, Fargate)
- references/diagnostic-commands.md — diagnostic command listings
- references/advanced-patterns.md — recent AWS features and expert-knowledge deep dives
- references/allocation-strategies-and-instance-selection.md — allocation strategies and instance selection (now includes expert heuristics)
- references/job-definitions-and-dependencies.md — job definitions and dependencies (now includes DAG heuristic and Step 7 CLI)
Domain
AWS CloudOps / AWS Batch Compute Environment, Job Queue, and Job Definition Provisioning & Workload Scheduling.
AWS documentation
- AWS Batch User Guide — https://docs.aws.amazon.com/batch/latest/userguide/what-is-batch.html
- Compute environments — https://docs.aws.amazon.com/batch/latest/userguide/compute_environments.html
- Allocation strategies — https://docs.aws.amazon.com/batch/latest/userguide/allocation-strategies.html
- Job queues — https://docs.aws.amazon.com/batch/latest/userguide/job_queues.html
- Job definitions — https://docs.aws.amazon.com/batch/latest/userguide/job_definitions.html
- Job dependencies — https://docs.aws.amazon.com/batch/latest/userguide/using_job_dependencies.html
- Array jobs — https://docs.aws.amazon.com/batch/latest/userguide/array_jobs.html
- Spot instances in Batch — https://docs.aws.amazon.com/batch/latest/userguide/spot_instances.html
- Batch on EKS — https://docs.aws.amazon.com/batch/latest/userguide/eks.html
- CloudWatch metrics — https://docs.aws.amazon.com/batch/latest/userguide/cloudwatch_metrics.html