Skip to main content

Running AWS Batch Jobs and Hybrid Compute

Run large jobs with AWS Batch on Fargate or Spot, extend AWS to your data center with Outposts, and use AppFlow, Amplify, and Instance Scheduler.

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
flowchart TD A([Submit job]) --> B[Job queue] B --> C[Scheduler] C --> D[Compute environment scales up] D --> E[Container runs] E --> F[(Results in S3)] E --> G[Compute scales down] classDef user fill:#8B5CF6,color:#ffffff classDef batch fill:#326CE5,color:#ffffff classDef out fill:#10B981,color:#ffffff class A user class B,C,D,G batch class E,F out

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
Remember

If 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
Tip

For 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.

flowchart LR A[On-premises apps] --> B[Outposts rack] B <-->|Service link| C[AWS parent Region] B --> D[(Local EBS and S3)] classDef onprem fill:#475569,color:#ffffff classDef out fill:#F97316,color:#ffffff classDef aws fill:#326CE5,color:#ffffff class A,D onprem class B out class C aws
  • 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 Mistake

Treating 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.

TEXT
Tag: Schedule=office-hours
Dev hours: Monday to Friday, 8 AM to 10 PM IST
Billed: about 300 of 720 hours a month, roughly 58 percent less

Stopped 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

Bash
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-1

Step 2: Create the job queue

Bash
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-1

Step 3: Register the job definition

The execution role needs the AmazonECSTaskExecutionRolePolicy managed policy, and you can create it in IAM first.

Bash
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-1

Step 4: Submit and watch the job

Bash
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 text

Run 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

Bash
aws batch update-job-queue --job-queue devops-batch-queue --state DISABLED --region ap-south-1
aws 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-1
aws 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-1

Wait 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 Mistake

Using Lambda for jobs that can pass 15 minutes. The function is stopped at its timeout. Run long jobs on Batch.

Common Mistake

Running 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.

Resources

AWS Direct Connect vs VPN: Run Both as Failover

AWS Direct Connect vs VPN: Run Both as Failover

Run AWS Direct Connect as primary and Site-to-Site VPN as BGP failover. Size the backup, set route preference and test it before an outage does.

10 min read•Aug 2026
Lambda vs Fargate vs EC2 Spot: The Cost Crossover

Lambda vs Fargate vs EC2 Spot: The Cost Crossover

Lambda vs Fargate vs EC2 Spot, at the crossover where Lambda stops being cheaper — 2026 pricing, invocation thresholds, and interruption math.

5 min read•Aug 2026
Secrets Manager vs Parameter Store vs Vault

Secrets Manager vs Parameter Store vs Vault

Secrets Manager vs Parameter Store vs Vault: cost math, rotation, dynamic secrets and a decision flow, plus the Vault, IBM and OpenBao licensing context.

10 min read•Aug 2026
AWS VPC Security: Hardening Every Layer

AWS VPC Security: Hardening Every Layer

Harden your AWS VPC in layers: subnets, Security Groups, NACLs, Flow Logs, endpoints, and IAM conditions, with CLI examples for production.

10 min read•Jul 2026
Event-Driven Architecture on AWS Explained

Event-Driven Architecture on AWS Explained

Build event-driven systems on AWS with SQS, SNS, EventBridge and Kinesis: fan-out, DLQs, idempotent consumers and queue-based scaling.

11 min read•Jul 2026
S3 vs RDS vs DynamoDB: Choosing AWS Storage

S3 vs RDS vs DynamoDB: Choosing AWS Storage

Choosing S3, RDS, or DynamoDB wrong costs you in performance, cost, and scalability. Here is a practical decision guide based on your actual access patterns.

5 min read•Jul 2026
AWS Cost Optimisation: 8 Actions That Cut Bills

AWS Cost Optimisation: 8 Actions That Cut Bills

Cut your AWS bill without re-architecting: eight ordered steps from anomaly alerts and tagging to rightsizing, VPC endpoints, Savings Plans and Spot.

11 min read•Jul 2026
EC2 vs Lambda vs Fargate: Choosing AWS Compute

EC2 vs Lambda vs Fargate: Choosing AWS Compute

Choose between EC2, Lambda and Fargate using traffic shape, state and runtime limits, with worked cost break-evens instead of rules of thumb.

11 min read•Jul 2026

Explore More in AWS DevOps, Cost, and Machine Learning

All 6 Topics

Frequently Asked Questions

Is Running AWS Batch Jobs and Hybrid Compute free to learn on DevOps Network?

Yes - this topic, like everything on DevOps Network, is 100% free with no paywall or sign-up gate.

What does the Running AWS Batch Jobs and Hybrid Compute topic cover?

Run large jobs with AWS Batch on Fargate or Spot, extend AWS to your data center with Outposts, and use AppFlow, Amplify, and Instance Scheduler.

Found a mistake, an outdated step or a broken link?