Overview and What You Will Learn
AWS Batch is a managed service that runs batch jobs of any length on compute it creates for you and removes when the work is done. This topic also covers AWS Outposts, which puts AWS infrastructure in your own data center, and three smaller services that save engineering time and money: AppFlow, Amplify and Instance Scheduler. In the lab you run a real Batch job on Fargate from the AWS CLI.
By the end you will be able to:
- Explain what Batch solves that Lambda and always-on EC2 do not
- Describe job definitions, job queues, compute environments and the job lifecycle
- Choose between Fargate and EC2 compute, and use Spot safely with retries
- Explain what Outposts is, when it fits, and what it needs from your network
- Use AppFlow for no-code SaaS data transfer and Amplify for full-stack hosting
- Cut non-production costs with Instance Scheduler
Why This Matters in Production
A broker such as Zerodha has end-of-day work, such as settlement calculations over millions of trades, that runs for hours once a day. Lambda stops at 15 minutes, and an EC2 fleet kept running all day would sit idle for most of it. Batch creates the compute when the job arrives, runs it to completion, and scales it back to zero.
Hybrid needs are different. A bank may have rules that keep certain data in its own building, or a factory may need single-digit millisecond responses from equipment. Outposts runs AWS services on AWS-owned hardware in your facility so you keep the same APIs and tools.
Core Principles
What Is AWS Batch and When Should You Use It Instead of Lambda?
AWS Batch runs containerized batch jobs at any scale, handling queuing, scheduling, retries and compute scaling. Use it for jobs that run longer than Lambda's 15-minute limit, need more than Lambda's 10 GB of memory, or process large volumes in parallel. Batch itself is free, and you pay only for the compute and storage your jobs use.
| Option | Limit or cost problem |
|---|---|
| Lambda | 15 minute maximum run, 10 GB memory |
| Always-on EC2 | Pay for idle hours |
| AWS Batch | No time limit, compute exists only while jobs run |
What Are Job Definitions, Job Queues, and Compute Environments?
Batch has three core pieces. A job definition describes what to run: the container image, command, vCPU and memory, and roles. A job queue holds submitted jobs and orders them by priority. A compute environment is the pool of compute, EC2 or Fargate, that runs the jobs.
- A higher-priority queue gets capacity first, so a production settlement queue can outrank a testing queue
- A managed compute environment lets Batch launch and scale the compute between the minimum and maximum vCPUs you set
- An unmanaged environment means you manage the instances yourself
- Array jobs run thousands of copies of one job with different indexes, which suits large parallel workloads
- Job dependencies let one job wait for another to succeed
A job moves through SUBMITTED, PENDING, RUNNABLE, STARTING, RUNNING and then SUCCEEDED or FAILED. A job stuck in RUNNABLE usually means the compute environment cannot start capacity, for example because of a subnet, quota or instance type problem.
Should You Run Batch on Fargate or EC2?
Use Fargate when you want no instances to manage and jobs fit its size limits, and use EC2 when you need GPUs, special instance types or the cheapest large-scale compute. Fargate has fast starts and no instance management, supports Fargate Spot, and handles jobs up to the Fargate task limits (16 vCPU and 120 GB memory at the time of writing, so check the current limits). Fargate has no GPU support, so ML training and GPU video work need EC2.
| Fargate | EC2 | |
|---|---|---|
| Management | None | Batch manages instances |
| GPUs | No | Yes |
| Best for | Many small to medium jobs | Large, GPU or tuned jobs |
RememberIf a job needs a GPU or more resources than the Fargate limits allow, use EC2 compute. Batch can also run on Amazon EKS if your team already works with Kubernetes.
How Do You Use Spot Instances with AWS Batch?
Spot capacity is spare EC2 capacity at a large discount, and Batch supports it natively, but Spot can be reclaimed so jobs must tolerate interruption. Savings can reach up to 90 percent compared with On-Demand. Allow many instance types and sizes and use the SPOT_PRICE_CAPACITY_OPTIMIZED allocation strategy, so Batch picks pools that are both cheap and unlikely to be interrupted.
- Set a job retry strategy with several attempts, because Batch does not retry on interruption by default
- Make jobs idempotent and checkpoint progress to S3 for long runs
- Keep a fallback On-Demand compute environment in the queue's environment order for jobs that must finish
TipFor embarrassingly parallel work, such as processing millions of files independently, combine array jobs, Spot and ten or more compatible instance types.
What Is AWS Outposts and What Does It Run?
Outposts is a fully managed service that installs AWS-designed hardware in your data center or colocation space, so you run AWS services locally with the same APIs and console. It comes as 42U racks or smaller 1U and 2U servers. AWS installs, monitors and patches the hardware, and you provide space, power, cooling and network.
Services include EC2, EBS, ECS, EKS, RDS and S3 on Outposts, and the list changes, so check the current docs for what your design needs.
- Local data processing: Process large data on site and send only results to the Region
- Low latency: Keep compute next to factory equipment or trading systems that cannot tolerate a trip to a Region
- Data residency: Keep data stores physically in your building when rules require it
Common MistakeTreating Outposts as fully independent. It depends on a reliable, redundant connection to its parent Region, using Direct Connect or internet connectivity, for management and the control plane. If the link drops, workloads already running keep running, but you cannot launch or manage resources through the Region APIs. Control plane metadata also lives in the Region, so confirm with your compliance team what data residency needs.
What Is AWS AppFlow?
AppFlow is a managed service that moves data between SaaS applications and AWS services with no code. It handles authentication, batching, field mapping, filtering, masking and encryption in transit. A flow can run on demand, on a schedule, or in response to an event.
- Sources include Salesforce, ServiceNow, Zendesk, Slack, SAP and Google Analytics
- Destinations include S3, Redshift, Snowflake and Salesforce
Example setup: create a flow from Salesforce Contacts to an S3 bucket, run it daily at 2 AM, mask sensitive fields, and map the field names.
What Is AWS Amplify?
Amplify is a toolset for building and deploying full-stack web and mobile apps on AWS. Amplify Hosting connects to a Git repository, builds your frontend (React, Vue, Angular or Next.js) on every push, serves it through a global CDN, manages domains and certificates, and creates preview environments for pull requests. Amplify also provides backend building blocks such as authentication with Cognito, APIs, storage on S3 and data on DynamoDB.
Use it when a frontend team wants to ship without managing infrastructure. Choose plain CloudFormation, CDK or Terraform when you need fine control of the backend.
How Does Instance Scheduler Cut Costs?
Instance Scheduler on AWS is a solution you deploy with CloudFormation that starts and stops EC2 and RDS instances on a schedule based on tags. Stopping non-production instances outside working hours can cut instance cost by more than half.
Tag: Schedule=office-hoursDev hours: Monday to Friday, 8 AM to 10 PM ISTBilled: about 300 of 720 hours a month, roughly 58 percent lessStopped instances still incur EBS storage charges, so savings apply to compute only.
Detailed Step-by-Step Practical Lab
This lab runs one job on Fargate in ap-south-1. Replace the subnet, security group and role values with your own, and use a public subnet with a public IP so the container can pull its image.
Step 1: Create the compute environment
aws batch create-compute-environment \ --compute-environment-name devops-batch-ce \ --type MANAGED \ --state ENABLED \ --compute-resources 'type=FARGATE,maxvCpus=16,subnets=[subnet-0abc1234],securityGroupIds=[sg-0abc1234]' \ --region ap-south-1Step 2: Create the job queue
aws batch create-job-queue \ --job-queue-name devops-batch-queue \ --state ENABLED \ --priority 1 \ --compute-environment-order order=1,computeEnvironment=devops-batch-ce \ --region ap-south-1Step 3: Register the job definition
The execution role needs the AmazonECSTaskExecutionRolePolicy managed policy, and you can create it in IAM first.
aws batch register-job-definition \ --job-definition-name devops-batch-job \ --type container \ --platform-capabilities FARGATE \ --container-properties 'image=public.ecr.aws/amazonlinux/amazonlinux:latest,command=[sh,-c,"echo started; sleep 10; echo done"],executionRoleArn=arn:aws:iam::123456789012:role/ecsTaskExecutionRole,resourceRequirements=[{type=VCPU,value=0.25},{type=MEMORY,value=512}],networkConfiguration={assignPublicIp=ENABLED}' \ --region ap-south-1Step 4: Submit and watch the job
JOB_ID=$(aws batch submit-job \ --job-name devops-test-job \ --job-queue devops-batch-queue \ --job-definition devops-batch-job \ --query jobId --output text \ --region ap-south-1) aws batch describe-jobs --jobs $JOB_ID --region ap-south-1 \ --query 'jobs[0].status' --output textRun the describe command again until the status reaches SUCCEEDED. The log group /aws/batch/job in CloudWatch Logs holds the echo output.
Step 5: Explore Amplify (read only)
Open AWS Amplify, choose Host web app, and review the Git provider options and branch-based deployment settings. You do not need to create an app.
Step 6: Clean up
aws batch update-job-queue --job-queue devops-batch-queue --state DISABLED --region ap-south-1aws batch delete-job-queue --job-queue devops-batch-queue --region ap-south-1 aws batch update-compute-environment --compute-environment devops-batch-ce --state DISABLED --region ap-south-1aws batch delete-compute-environment --compute-environment devops-batch-ce --region ap-south-1 aws batch deregister-job-definition --job-definition devops-batch-job:1 --region ap-south-1Wait for the queue to finish deleting before you delete the compute environment.
Production Best Practices & Common Pitfalls
- Use Batch for long or heavy jobs: Lambda is for short tasks, and Batch for hours-long or large parallel work.
- Set a retry strategy: Spot interruptions and transient failures need retries.
- Allow many instance types: More choices give Spot more capacity and lower cost.
- Right-size vCPU and memory: Over-sized jobs waste money and under-sized jobs fail.
- Use queue priorities and fair-share scheduling: Protect production work from experiments.
- Plan Outposts capacity and connectivity: Capacity is fixed, so size it up front and give it a redundant link.
- Check data residency rules with compliance: Do not assume Outposts alone satisfies them.
- Tag non-production resources for Instance Scheduler: The savings need the tags.
Common MistakeUsing Lambda for jobs that can pass 15 minutes. The function is stopped at its timeout. Run long jobs on Batch.
Common MistakeRunning Spot jobs with no retry strategy. An interruption then fails the job for good.
Quick Reference & Troubleshooting Commands
| Task | Command |
|---|---|
| List job queues | aws batch describe-job-queues |
| List compute environments | aws batch describe-compute-environments |
| List jobs in a queue | aws batch list-jobs --job-queue <queue> --job-status RUNNING |
| Describe a job | aws batch describe-jobs --jobs <job-id> |
| Cancel a job | aws batch cancel-job --job-id <id> --reason "manual cancel" |
| Terminate a running job | aws batch terminate-job --job-id <id> --reason "stop" |
| Problem | Likely cause and fix |
|---|---|
| Job stuck in RUNNABLE | Compute cannot start capacity. Check subnets, quotas, instance types and max vCPUs. |
| Fargate job cannot pull image | No route to the registry. Use a public IP or a NAT Gateway. |
| Job fails with access denied | Missing execution or job role permissions. |
| Spot job failed once and stopped | No retry strategy. Add attempts and retry on host termination. |
| Outposts instance cannot launch | Region link down or no free capacity on the Outpost. |