Serverless compute engine for containers that eliminates server management, allowing Docker container execution paying only for consumed resources.
AWS Fargate is a serverless compute engine for containers that works with ECS and EKS. It completely eliminates the need to provision, configure, and manage EC2 instances. You define CPU and memory for your container, and Fargate handles all the underlying infrastructure.
Fargate represents a fundamental shift in how we run containers in the cloud: from managing server clusters to simply specifying resources. This abstraction allows teams to focus on their applications rather than infrastructure, accelerating development and reducing operational complexity.
Fargate's architecture is built on a multi-tenant infrastructure that completely isolates tasks from each other, providing hypervisor-level security while maintaining the flexibility of Docker containers.
Fargate charges per second with a 1-minute minimum billing:
On-Demand:
Fargate Spot (up to 70% discount):
Web application: 0.5 vCPU, 1GB RAM, running 24/7
| Mode | Monthly cost | Savings |
|---|---|---|
| On-Demand | $17.50 | - |
| Spot | $5.25 | 70% |
Batch job: 2 vCPU, 4GB RAM, 100 hours/month
| Mode | Monthly cost | Savings |
|---|---|---|
| On-Demand | $25.89 | - |
| Spot | $7.77 | 70% |
| vCPU | Available memory |
|---|---|
| 0.25 | 0.5GB, 1GB, 2GB |
| 0.5 | 1GB - 4GB (1GB increments) |
| 1 | 2GB - 8GB (1GB increments) |
| 2 | 4GB - 16GB (1GB increments) |
| 4 | 8GB - 30GB (1GB increments) |
| 8 | 16GB - 60GB (4GB increments) |
| 16 | 32GB - 120GB (8GB increments) |
For web applications:
For batch jobs:
For microservices:
Fargate only supports awsvpc mode, where each task receives:
{
"networkConfiguration": {
"awsvpcConfiguration": {
"subnets": ["subnet-12345", "subnet-67890"],
"securityGroups": ["sg-web-tier", "sg-app-specific"],
"assignPublicIp": "DISABLED"
}
}
}Each task can have multiple security groups, enabling:
/tmp and container layersFor persistent storage:
{
"volumes": [
{
"name": "efs-volume",
"efsVolumeConfiguration": {
"fileSystemId": "fs-12345678",
"transitEncryption": "ENABLED",
"authorizationConfig": {
"accessPointId": "fsap-12345678"
}
}
}
],
"containerDefinitions": [
{
"mountPoints": [
{
"sourceVolume": "efs-volume",
"containerPath": "/data"
}
]
}
]
}| Dimension | Fargate | EC2 Launch Type |
|---|---|---|
| Operational overhead | Zero — AWS manages everything | High — patching, scaling, monitoring |
| Scaling speed | Seconds (cold start ~30s) | Minutes (instance launch) |
| Cost break-even | Under 50% utilization | Over 50% constant utilization |
| Resource granularity | Per individual task | Per complete instance |
| Security isolation | Hypervisor-level | Shared kernel |
| Configuration flexibility | Limited to Fargate options | Full host control |
| Time to production | Days | Weeks |
Fargate is ideal for:
EC2 is better for:
# Capacity provider with Fargate Spot
resource "aws_ecs_capacity_provider" "fargate_spot" {
name = "FARGATE_SPOT"
}
resource "aws_ecs_cluster_capacity_providers" "main" {
cluster_name = aws_ecs_cluster.main.name
capacity_providers = ["FARGATE", "FARGATE_SPOT"]
default_capacity_provider_strategy {
capacity_provider = "FARGATE_SPOT"
weight = 4
base = 0
}
default_capacity_provider_strategy {
capacity_provider = "FARGATE"
weight = 1
base = 1
}
}
# Task definition optimized for Spot
resource "aws_ecs_task_definition" "batch_job" {
family = "batch-processor"
network_mode = "awsvpc"
requires_compatibilities = ["FARGATE"]
cpu = 1024
memory = 2048
execution_role_arn = aws_iam_role.execution.arn
task_role_arn = aws_iam_role.task.arn
ephemeral_storage {
size_in_gib = 50
}
container_definitions = jsonencode([
{
name = "processor"
image = "my-batch-processor:latest"
logConfiguration = {
logDriver = "awslogs"
options = {
"awslogs-group" = "/ecs/batch-processor"
"awslogs-region" = "us-east-1"
"awslogs-stream-prefix" = "ecs"
}
}
environment = [
{
name = "SPOT_INSTANCE"
value = "true"
}
]
}
])
}Enables detailed metrics automatically:
{
"containerDefinitions": [
{
"logConfiguration": {
"logDriver": "awslogs",
"options": {
"awslogs-group": "/aws/ecs/containerinsights/cluster-name/performance"
}
}
}
]
}Fargate represents the natural evolution of container computing toward a fully serverless model. For most teams, it eliminates weeks of infrastructure setup and maintenance work, allowing focus on code that generates business value. Its per-second pricing model and Spot capacity make it economically viable for a wide range of workloads. However, for applications with high constant utilization (>70%), EC2 may still be more economical. The choice between Fargate and EC2 isn't technical but strategic: do you prefer to optimize for development speed or operational cost?
AWS container orchestration service that runs and scales Docker applications without managing the underlying cluster infrastructure.
Cloud computing model where the provider manages infrastructure automatically, allowing code execution without provisioning or managing servers, paying only for actual usage.
Container platform that packages applications with all dependencies into portable, consistent units that run identically in any environment.
Collection of 13 Terraform modules published on the Terraform Registry for deploying serverless architectures on AWS, with 12 examples covering basic ECS to full-stack CRUD with DynamoDB and AgentCore with MCP.