AWS Fargate
A serverless container execution environment
A serverless container execution environment
AWS Fargate is a serverless compute engine for containers. It lets you run containers without provisioning or managing EC2 instances. You only specify the vCPU and memory required for a Task (or Pod), and AWS automatically allocates and manages the appropriate infrastructure.
It was launched for ECS at re:Invent 2017, and has also been available for EKS since 2019. As the service that first commercialized the concept of "serverless containers" at AWS, it completely eliminates the complexity of running containers on EC2 (patching, scaling, capacity planning).
Fargate provides a dedicated isolated environment (microVM) for each Task. Based on Firecracker technology, it provides VM-level isolation while achieving container-level fast startup times (usually within 30 seconds). It is suitable for security-critical workloads in multi-tenant environments.
Billing is per second, based on vCPU and memory usage. Although the cost per GB is higher than EC2, there is no overprovisioning and no operational overhead, so the total cost of ownership (TCO) may actually be lower. It is especially cost-effective for variable workloads or when there are many small containers.
{
"family": "my-fargate-task",
"networkMode": "awsvpc",
"requiresCompatibilities": ["FARGATE"],
"cpu": "512",
"memory": "1024",
"executionRoleArn": "arn:aws:iam::123456789:role/ecsTaskExecutionRole",
"taskRoleArn": "arn:aws:iam::123456789:role/myAppTaskRole",
"containerDefinitions": [
{
"name": "my-app",
"image": "123456789.dkr.ecr.ap-northeast-2.amazonaws.com/my-app:latest",
"essential": true,
"portMappings": [
{
"containerPort": 8080,
"protocol": "tcp"
}
],
"logConfiguration": {
"logDriver": "awslogs",
"options": {
"awslogs-group": "/ecs/my-fargate-task",
"awslogs-region": "ap-northeast-2",
"awslogs-stream-prefix": "ecs"
}
},
"environment": [
{"name": "NODE_ENV", "value": "production"}
],
"secrets": [
{
"name": "DB_PASSWORD",
"valueFrom": "arn:aws:secretsmanager:ap-northeast-2:123456789:secret:db-password"
}
],
"healthCheck": {
"command": ["CMD-SHELL", "curl -f http://localhost:8080/health || exit 1"],
"interval": 30,
"timeout": 5,
"retries": 3
}
}
]
}
"This service has an irregular traffic pattern and the load is high only during peak times, so Fargate is a good fit. With an EC2 node group, there would be many instances sitting idle most of the time, whereas Fargate bills per Task for exactly what's needed. The cold start is around 30 seconds, but if we always keep a minimum of 2 running, there's no problem for the user experience."
"I have experience running 20 microservices on ECS Fargate. I integrated Secrets Manager per container in the Task Definition, and applied a scaling policy based on 70% CPU with Service Auto Scaling. The operational burden was greatly reduced compared to EC2, and I switched the nightly batch jobs to Fargate Spot, saving 70% in costs."
"Fargate has a higher vCPU unit price than EC2, but our workload's average CPU utilization is only 20%. With EC2 you always pay 100% of the cost, whereas Fargate bills only for actual usage, so the total cost is actually lower. On top of that, you also save the cost of the DevOps staff who patch EC2 and manage AMIs."
Take a mock interview on this topic → WIA SOOM AI Interview · Start for free
Fargate does not support GPUs, Inferentia, or Custom AMIs. GPU workloads such as ML inference or video encoding must use EC2-based infrastructure. Also, when large ephemeral storage is needed, Fargate supports up to only 200GB.
Fargate has fixed vCPU/memory combinations. For example, 0.25 vCPU can only be paired with 0.5-2GB of memory. If you request an unsupported combination, the Task will not start, so check the supported combinations in the AWS documentation.
Use the awsvpc network mode to assign an ENI to each Task, and strengthen security with a Private Subnet + NAT Gateway configuration. Setting up a VPC Endpoint for ECR image pulls also saves NAT costs.