Chapter 89: Amazon ECS for DevOps
89.3 EC2 launch type vs Fargate
Story. Omar in Hyderabad had bursty batch jobs at month end. On ECS EC2 launch type, he managed an Auto Scaling group of instances — cheaper at steady high use, but he patched AMIs. Sara in Austin ran a public API on Fargate. She paid per vCPU and memory second, never SSH'd to a box, and slept during patch Tuesdays. Same ECS service API — different capacity model. Pick with cost and ops honesty, and treat every price as approximate.
Why
Compute is usually the big bill. The launch type decides who manages the machines under your tasks.
What
- Launch type / capacity provider — How tasks get CPU and memory: EC2 or FARGATE (and related capacity providers).
- EC2 launch type — Tasks land on ECS container instances you (or ASG) manage.
- Fargate — AWS runs the isolation for each task; you choose CPU/memory sizes from the Fargate table.
- awsvpc network mode — Common on Fargate: each task gets its own elastic network interface in your VPC.
How
- For labs and variable traffic with a small ops team: prefer Fargate.
- For large steady fleets where you already run EC2 well: compare EC2 launch type costs.
- Set CPU and memory to the smallest size that passes load tests.
- Delete idle services and clusters so lab spend stops the same day.
Example 1: Run a one-off Fargate task (shape)
aws ecs run-task --cluster shop-lab --launch-type FARGATE --task-definition pay-api:7 \
--network-configuration "awsvpcConfiguration={subnets=[subnet-aaa,subnet-bbb],securityGroups=[sg-ccc],assignPublicIp=DISABLED}" \
--region ap-south-1
Output
{
"tasks": [
{
"taskArn": "arn:aws:ecs:ap-south-1:123456789012:task/shop-lab/abcd",
"lastStatus": "PROVISIONING",
"launchType": "FARGATE"
}
]
}
What it shows: ECS accepted a Fargate task. Status moves PROVISIONING → PENDING → RUNNING. Subnet and SG ids are placeholders.
Example 2: Capacity provider strategy on a service (idea)
capacityProviderStrategy:
- capacityProvider: FARGATE
weight: 1
- capacityProvider: FARGATE_SPOT
weight: 1
(approximate savings on Spot — check current Fargate Spot rules and interruption behaviour)
What it shows: You can mix providers. Spot is cheaper but can be interrupted — use for fault-tolerant work, not every payment API.
Ravindra Bagale's Tip
Fargate reduces instance babysitting. EC2 launch type can win on cost at high steady utilisation — verify with a current pricing calculator.
Fargate = कमी instance काम. High steady use ला EC2 launch type स्वस्त पडू शकतो — pricing calculator तपासा.
Fargate = कम instance काम. High steady use पर EC2 launch type सस्ता पड़ सकता है — pricing calculator देखें.
Quick quiz
Q1. What is Fargate on ECS?
AWS-managed capacity for tasks so you do not run ECS container instances yourself.
Q2. What do you manage on EC2 launch type?
The EC2 (or ASG) capacity that hosts tasks, including patching and scaling instances.
Q3. Why mention Fargate Spot carefully?
Lower approximate price but tasks can be interrupted — unfit for every workload.
Did you understand? Let us try it once more.