What Is Amazon ECS and Fargate? Run Docker Without Servers
Swiggy packs each kitchen order in a box. Docker packs your app the same way. ECS is the kitchen manager that runs many boxes. Fargate means AWS owns the kitchen machines — you only bring the boxes.
What you'll learn in this chapter
- Why teams moved from one fat EC2 to many containers
- What cluster, task definition, task and service mean
- Fargate vs EC2 launch type
- ECS vs Lambda vs EKS — when to pick
- Pricing shape and a tiny mental lab path
1. Everyday example first
Why do we need this?
Flipkart Black Friday traffic spikes. One big EC2 with Node, Redis and cron is hard to scale and hard to replace. Containers let you ship the same image to many small workers and kill them when the sale ends.
What is it?
Docker packages code + libs into an image. A running image is a container. Amazon ECS (Elastic Container Service) starts, stops and restarts containers on AWS. Fargate is a launch type where you do not manage EC2 for those containers.
2. Core words
| Word | Meaning | Kitchen |
|---|---|---|
| Cluster | A home for your services | One restaurant brand |
| Task definition | Recipe: image, CPU, memory, ports, env | Recipe card |
| Task | One running copy of that recipe | One order being cooked |
| Service | Keep N tasks running; replace unhealthy | Always 4 chefs on shift |
| Launch type | Fargate (no EC2) or EC2 (you manage) | Rented kitchen vs own |
3. Fargate vs EC2 launch type
Why do we need this?
Wrong launch type wastes money or ops time.
What is it?
| Need | Prefer | Why |
|---|---|---|
| Student lab, spiky API, little ops time | Fargate | No AMI, no ASG, pay per task vCPU/memory |
| Steady 24×7 fleet, GPU, special kernel | EC2 launch type | Cheaper at huge steady load; more control |
| Same image on laptop and cloud | Either — image is the same | Portability comes from Docker |
Ravindra Bagale's Tip
Start labs on Fargate. Move to EC2 launch type only when a cost spreadsheet says so.
4. ECS vs Lambda vs EKS
- Lambda: seconds of work, event-driven, 15 min max, no long processes.
- ECS: minutes-to-days containers, custom processes, sidecars, familiar Docker.
- EKS: full Kubernetes API when you already live in k8s or need multi-cloud k8s skills.
5. Pricing shape (mental model)
Fargate bills for vCPU and memory while the task runs. Idle service with desired count 0 costs almost nothing. ALB, NAT, ECR storage and data transfer are extra. Always set desired count to 0 or delete the service after a lab.
6. Interview angles
Q. What is a task definition?
JSON recipe: image, CPU, memory, ports, IAM roles, env.
Q. Service vs task?
Task is one run; service keeps N healthy tasks.
Q. Why Fargate?
No EC2 to patch; pay per running task.
Q. ECS vs EKS?
ECS is AWS-native and simpler; EKS is Kubernetes-compatible.
Q. Where do images live?
Usually Amazon ECR in the same region.
Try at home
- Draw cluster → service → tasks → containers on paper.
- Read the next chapter and deploy nginx on Fargate.
In short
- ECS runs Docker containers on AWS.
- Fargate = no EC2 management for those tasks.
- Task definition is the recipe; service keeps N running.
- Clean up labs — Fargate bills while tasks run.
Practice Tasks
Milan Furniture is a furniture business in Milan. Giulia Rossi looks after its IT and cloud work. They count money in EUR and run their AWS resources in the eu-south-1 Region. In the tasks below you do real jobs for them using what this lesson teaches. All names, account IDs, IP addresses and numbers are made up for practice.
0 / 10
Easy Create an ECS cluster
Why: A cluster is the logical home for your services and tasks.
What to do: Create an ECS cluster named milanfurniture-cluster.
- Read the task and decide which AWS service it is about.
- Write aws, then the service name, then the operation (the action word).
- Add each needed flag (--name) followed by its value from the task.
- Flags can be in any order. Click Check answer.
Easy Create an ECR repository
Why: ECR stores your Docker images privately inside AWS.
What to do: Create an ECR repository named milanfurniture/web.
- Read the task and decide which AWS service it is about.
- Write aws, then the service name, then the operation (the action word).
- Add each needed flag (--name) followed by its value from the task.
- Flags can be in any order. Click Check answer.
Easy List running tasks
Why: See which tasks are running in a cluster.
What to do: List the tasks in cluster milanfurniture-cluster.
- Read the task and decide which AWS service it is about.
- Write aws, then the service name, then the operation (the action word).
- Add each needed flag (--name) followed by its value from the task.
- Flags can be in any order. Click Check answer.
Medium Register a task definition
Why: The task definition says which image, CPU, memory and ports a container uses.
What to do: Register the task definition in taskdef.json.
- Read the task and decide which AWS service it is about.
- Write aws, then the service name, then the operation (the action word).
- Add each needed flag (--name) followed by its value from the task.
- Flags can be in any order. Click Check answer.
Medium Pull images from one repository
Why: CI or servers should pull only the images they run.
What to do: Allow ecr:BatchGetImage and ecr:GetDownloadUrlForLayer on arn:aws:ecr:eu-south-1:126154182628:repository/milanfurniture/web, plus ecr:GetAuthorizationToken on *.
- Start with { "Version": "2012-10-17", "Statement": [ ... ] }.
- In each statement write Effect, Action and Resource.
- Give only what the task needs (least privilege).
- Use double quotes and commas correctly. Click Check answer.
Medium Scale a service
Why: Change desired count to run more copies of the container.
What to do: Set service web in cluster milanfurniture-cluster to 4 tasks.
- Read the task and decide which AWS service it is about.
- Write aws, then the service name, then the operation (the action word).
- Add each needed flag (--name) followed by its value from the task.
- Flags can be in any order. Click Check answer.
Medium Trust policy for an ECS task role
Why: The trust policy says WHO may take the role.
What to do: Write a trust policy that lets ecs-tasks.amazonaws.com assume the role.
- Start with { "Version": "2012-10-17", "Statement": [ ... ] }.
- In each statement write Effect, Action and Resource.
- Give only what the task needs (least privilege).
- Use double quotes and commas correctly. Click Check answer.
Medium Redeploy a service
Why: force-new-deployment restarts tasks so they pull the latest image.
What to do: Force a new deployment of service web in cluster milanfurniture-cluster.
- Read the task and decide which AWS service it is about.
- Write aws, then the service name, then the operation (the action word).
- Add each needed flag (--name) followed by its value from the task.
- Flags can be in any order. Click Check answer.
Medium Get the ECR login password
Why: Docker needs a short-lived password before it can push to ECR.
What to do: Get the ECR login password for eu-south-1.
- Read the task and decide which AWS service it is about.
- Write aws, then the service name, then the operation (the action word).
- Add each needed flag (--name) followed by its value from the task.
- Flags can be in any order. Click Check answer.
Hard Create a Fargate service
Why: A service keeps the desired number of tasks running and replaces failed ones.
What to do: In cluster milanfurniture-cluster, create service web using task definition milanfurniture-web:1, 2 tasks, launch type FARGATE, network config from net.json.
- Read the task and decide which AWS service it is about.
- Write aws, then the service name, then the operation (the action word).
- Add each needed flag (--name) followed by its value from the task.
- Flags can be in any order. Click Check answer.
Revision, comparison and interview cards
Revise this lesson in a few minutes. Save the cards on your phone or download them as PNG files. The QR code on each card opens this lesson.







More cards: Ravi Sir's Cards.