Lesson 9 of 9 Data Engineering Practices

Running Data Processing in Containers and AWS Batch

This lesson explains how containers on Amazon ECS or Amazon EKS, and AWS Batch, run processing that does not fit Glue or Lambda, and how to size and run them efficiently.

Learning outcomes

After completing this lesson, you will be able to:

  • Choose between Amazon ECS, Amazon EKS and AWS Batch.
  • Size containers and use Fargate Spot to reduce cost.
  • Replace a Lambda function that exceeds its time limit.

Choosing a container option

Amazon ECS is AWS's own container orchestrator and the simplest way to run containerised tasks, such as a nightly extract or a long-running stream consumer. Amazon EKS runs Kubernetes, which suits teams that already use Kubernetes tooling; EMR on EKS runs Spark jobs on an existing EKS cluster, sharing it with other workloads. Both run on AWS Fargate, which removes servers entirely and bills per task's vCPU and memory, or on EC2 instances, which suit GPUs, very large tasks or heavy steady use where Reserved or Spot capacity is cheaper. Images are stored in Amazon ECR.

AWS Batch schedules large numbers of batch jobs. Jobs are submitted to a job queue, and Batch provisions a compute environment on Fargate, EC2 or Spot capacity just large enough to run them, then scales it to zero. Array jobs run the same container over thousands of inputs, such as one job per file, and Step Functions and EventBridge can submit jobs. The following table summarises the options.

OptionSuits
ECS on FargateContainerised tasks with no servers; long-running or over-15-minute jobs
EKS (including EMR on EKS)Teams using Kubernetes; Spark sharing a Kubernetes cluster
EC2 capacity for ECS or EKSGPUs, very large tasks, steady heavy use with Reserved or Spot pricing
AWS BatchMany queued batch jobs, array jobs over many inputs, Spot-based cost savings

The following diagram shows a design that replaces a Lambda function with AWS Batch for long-running file processing.

Replacing the Lambda function with AWS Batch. The same code is packaged as a container image in ECR. Each upload's S3 event goes through EventBridge, which submits a Batch job to a job queue on a Fargate Spot compute environment, so files of several gigabytes are no longer cut off at 15 minutes and the team pays only while jobs run.
The scenario is illustrative.
Match the pairs

Container options

Exam skills 1.2.1

Match each workload with the container option that fits it.

Log in to try this activity Interactive activities are free with an account.

Optimizing container usage

Container performance and cost depend mainly on sizing. Each task should request the CPU and memory it actually uses, measured with CloudWatch Container Insights; oversized tasks waste money, and undersized ones are killed when they exceed their memory. Work that can be split should run as many small parallel tasks, or a Batch array job, rather than one large task. Interruptible work can run on Fargate Spot or EC2 Spot capacity at a large discount, and Graviton (Arm) images often give better price performance. Smaller images, built from slim base images, start faster, and services scale task counts automatically with Application Auto Scaling, for example on queue depth. The following list summarises the practices.

  • Right-size task CPU and memory from Container Insights metrics.
  • Parallelise across many small tasks or Batch array jobs.
  • Use Fargate Spot or EC2 Spot for interruptible work, and Graviton where images support it.
  • Keep images small so tasks start quickly.
  • Scale the number of tasks with demand, for example on SQS queue depth.
Select all that apply

Optimising containers

Exam skills 1.2.1 · 1.2.4

Identify good practices for container-based data processing.

Log in to try this activity Interactive activities are free with an account.
Worked example

Replacing a Lambda function that times out

A Lambda function converts uploaded video metadata files, but files of several gigabytes take longer than 15 minutes and fail. The team packages the same code as a container image in ECR and has an S3 event, through EventBridge, submit an AWS Batch job on a Fargate Spot compute environment for each file. Small files still finish in minutes, large files are no longer cut off, and the team pays only while jobs run, at Spot prices.

aws batch submit-job --job-name convert-2026-10-16 --job-queue media-queue \
  --job-definition convert-metadata:3 \
  --container-overrides 'command=["python","convert.py","s3://raw/media/file-0042.json"]'
Check yourself

Which service runs many queued jobs, such as one job per file?

Show answer

AWS Batch, with array jobs.

Exam Tips

Remember for the exam

  • Containerised or over-15-minute processing with no servers: ECS on Fargate.
  • Existing Kubernetes platform, or Spark sharing it: EKS or EMR on EKS.
  • Many queued batch jobs or one job per file: AWS Batch with array jobs.
  • Cut container cost with right-sizing, Fargate Spot or EC2 Spot, and Graviton.