When to Use Fargate
Guidelines for choosing Fargate over the EC2 launch type.
Fargate shines when you value simplicity and elastic scaling over fine-grained host control.
Reach for Fargate when
- You do not want to manage servers or patch AMIs.
- Traffic is spiky and you want to scale tasks quickly.
- You run many small, isolated workloads.
Prefer EC2 when
- You run steady, high-density workloads and want lower cost.
- You need GPUs, special instance types, or host-level access.
Example
# A Fargate service that scales tasks, not servers
aws ecs create-service \
--cluster prod --service-name api \
--task-definition api:7 --desired-count 4 \
--launch-type FARGATE \
--network-configuration 'awsvpcConfiguration={subnets=[subnet-abc]}'When to use it
- A team building a new service with unpredictable traffic starts with Fargate to avoid over-provisioning EC2 capacity they may not need.
- An ML team chooses EC2 launch type instead of Fargate for training jobs because they need P3 GPU instances that Fargate does not offer.
- A company running hundreds of small, short-lived batch jobs prefers Fargate to avoid the EC2 instance management overhead that adds no business value.
More examples
Check if Fargate Supports Your CPU/Memory
Lists the valid Fargate CPU and memory combinations so you can validate your task definition before registration.
# Valid Fargate CPU/memory combinations:
# 256 CPU -> 512, 1024, 2048 MB
# 512 CPU -> 1024-4096 MB (1 GB increments)
# 1024 CPU -> 2048-8192 MB (1 GB increments)
# 2048 CPU -> 4096-16384 MB (1 GB increments)
# 4096 CPU -> 8192-30720 MB (1 GB increments)
echo "Choose a valid Fargate combination"Fargate Service for Unpredictable Traffic
Creates a Fargate service ideal for unpredictable workloads where you want instant scaling without pre-provisioned EC2 instances.
aws ecs create-service \
--cluster prod \
--service-name web-frontend \
--task-definition frontend:8 \
--launch-type FARGATE \
--desired-count 2 \
--network-configuration \
'awsvpcConfiguration={subnets=[subnet-a,subnet-b],securityGroups=[sg-web],assignPublicIp=DISABLED}'EC2 Launch Type for GPU Workloads
Creates a service on the EC2 launch type constrained to P3 GPU instances, which are not available on Fargate.
aws ecs create-service \
--cluster gpu-cluster \
--service-name ml-inference \
--task-definition ml-model:1 \
--launch-type EC2 \
--desired-count 1 \
--placement-constraints \
'[{"type":"memberOf","expression":"attribute:ecs.instance-type =~ p3.*"}]'
Discussion