Dung (Donny) Nguyen

Senior Software Engineer

Fargate and EC2 in AWS ECS

When running containers on Amazon ECS (Elastic Container Service), we choose a launch type that determines where and how our containers run. The two main options are AWS Fargate and EC2. Both run the same container images and use the same task definitions, but they differ in how the underlying compute is provisioned and managed.

AWS Fargate

AWS Fargate is a serverless compute engine for containers. We define our tasks, and Fargate provisions and manages the underlying infrastructure automatically. There are no servers to patch, scale, or maintain.

Key characteristics:

Best for:

EC2 Launch Type

With the EC2 launch type, our containers run on a cluster of Amazon EC2 instances that we provision and manage. ECS schedules tasks onto these instances, but we are responsible for the instances themselves.

Key characteristics:

Best for:

Fargate vs EC2

Aspect Fargate EC2
Infrastructure management Managed by AWS Managed by us
Server patching & scaling Handled automatically Our responsibility
Billing model Per task (vCPU + memory, per second) Per EC2 instance (running time)
Control over host None Full control
Instance/hardware choice Not applicable Custom instance types, GPUs, etc.
Scaling speed Fast, per-task Depends on instance provisioning
Cost efficiency Great for variable workloads Great for steady, high-density workloads
Operational overhead Minimal Higher
Best use case Simplicity, variable traffic Control, cost tuning at scale

How to Choose

Many organizations use a mix of both: Fargate for spiky or unpredictable services and EC2 for steady, cost-sensitive, or hardware-specific workloads. Because both launch types share the same task definitions, we can move workloads between them with relatively little effort.

Conclusion

Fargate and EC2 give us two ways to run containers on ECS with a trade-off between simplicity and control. Fargate removes infrastructure management and is ideal for agility and variable workloads, while EC2 offers deeper control and cost optimization for steady, specialized workloads. Understanding these differences helps us pick the right launch type — or combination — for each application.