Choosing EC2 or Fargate Capacity for Containers
This lesson explains the capacity options for containers, EC2 instances you manage and serverless Fargate, including Fargate Spot for interruptible tasks.
Learning outcomes
After completing this lesson, you will be able to:
- Distinguish the EC2 launch type from Fargate.
- Describe Fargate characteristics.
- Choose a container platform.
The options
Containers can run on capacity that ranges from fully self-managed to fully managed. With the EC2 launch type, you run the container instances: you choose instance types, including GPU instances, patch and scale them, and can buy them with Reserved Instances, Savings Plans or Spot. It gives the most control and the highest utilisation when many tasks share instances.
With Fargate, there are no instances to manage; you pay for the vCPU and memory each task requests, which gives the least operational overhead. Fargate Spot runs interruptible tasks on spare capacity at a large discount, with two minutes' notice before a task is stopped. The following table summarises the options.
| Option | You manage | Best for |
|---|---|---|
| EC2 launch type | Container instances, types, GPUs; RIs or Spot | Control, GPUs, specific instance types, highest utilisation |
| Fargate | Nothing: pay per task vCPU and memory | Least operational overhead |
| Fargate Spot | Nothing; tasks can be interrupted with two minutes' notice | Interruptible tasks at up to 70% discount |
EC2, Fargate or Fargate Spot?
Fargate characteristics
AWS Fargate runs containers without servers to manage. Each task or pod runs in its own isolated environment with its own network interface, in awsvpc networking mode, which gives strong isolation between workloads. There are no instances to patch, scale or right-size; the customer chooses the CPU and memory for each task, and Compute Savings Plans apply.
Fargate has limitations that rule it out for some workloads: it offers no GPUs, does not allow privileged containers, and gives no access to the underlying host. Workloads that need any of these run on EC2 capacity instead.
What rules Fargate out
Choosing a container platform
The appropriate container platform depends on the team's existing tooling and operational requirements. The following table identifies the choice suited to several situations.
| Situation | Choice |
|---|---|
| A small team wants to run containers with the least operational effort | ECS on Fargate |
| The company already runs Kubernetes on premises and wants the same tooling | EKS (with Fargate or managed node groups) |
| Steady, large container fleet where cost per vCPU matters most | ECS or EKS on EC2 with Savings Plans or Spot |
| Containers need GPUs | ECS or EKS on EC2 GPU instances (Fargate does not offer GPUs) |
Fargate removes server management entirely: no instances to patch or scale. EC2 launch types give more control and can be cheaper at scale, at the cost of managing the cluster's instances.
What does Fargate remove from the team's work?
Show answer
Managing servers: there are no instances to provision, patch or scale, because each task runs on capacity that AWS manages.
Exam Tips
Remember for the exam
- For containers with the least operational overhead, use ECS on Fargate.
- When containers need GPUs or particular instance types, use the EC2 launch type.
- For interruptible container tasks at the lowest cost, use Fargate Spot.
- To deploy a web application from code with managed infrastructure, use Elastic Beanstalk.