aws_ ecs_ service cost estimation
A long-running ECS service. Cost depends on launch type: EC2 (pay for nodes), Fargate (pay per task vCPU/memory), or Fargate Spot.
An aws_
ECS supports three launch types with very different cost profiles:
EC2 launch type: tasks run on EC2 instances you manage (registered to an ECS cluster). You pay regular EC2 prices for the instances plus EBS for any volumes. Higher operational burden but lowest cost per unit of compute. Right when you can keep node utilization high.
Fargate launch type: AWS provisions per-task compute. You pay per task by requested vCPU and memory. Per-vCPU-hour rates are higher than equivalent on-demand EC2, but you only pay for what tasks actually use. Right for unpredictable, low-utilization, or simple workloads.
Fargate Spot: same as Fargate but with up-to-70%-off pricing for fault-tolerant workloads. Tasks can be interrupted with 2-minute notice. Excellent for batch jobs and stateless services.
The service's desired_
Additional costs for ECS services typically include: load balancers (each Service usually has an aws_
c3x reads the linked task definition's cpu and memory and the desired_
Terraform example
A minimal but realistic configuration that C3X can estimate.
resource "aws_ecs_cluster" "main" {
name = "production"
}
resource "aws_ecs_task_definition" "api" {
family = "api"
network_mode = "awsvpc"
requires_compatibilities = ["FARGATE"]
cpu = 1024
memory = 2048
execution_role_arn = aws_iam_role.ecs_execution.arn
container_definitions = jsonencode([{
name = "api"
image = "my-org/api:v1.2.3"
essential = true
portMappings = [{
containerPort = 8080
}]
}])
}
resource "aws_ecs_service" "api" {
name = "api"
cluster = aws_ecs_cluster.main.id
task_definition = aws_ecs_task_definition.api.arn
desired_count = 3
launch_type = "FARGATE"
network_configuration {
subnets = aws_subnet.private[*].id
security_groups = [aws_security_group.tasks.id]
}
}Pricing dimensions
What you actually pay for when you provision aws_.
| Dimension | Unit | What's being charged |
|---|---|---|
| Fargate vCPU-hours | per vCPU-hour | Per-task vCPU as specified in the task definition. Billed continuously while tasks run. $0.04048/vCPU-hour in us-east-1 |
| Fargate memory-hours | per GB-hour | Per-task memory as specified in the task definition. $0.004445/GB-hour |
| Fargate Spot | per vCPU-hour and per GB-hour | Same dimensions as Fargate but discounted up to 70% with interruption risk. |
| EC2 launch type | per instance hour | Tasks run on EC2 instances. Standard EC2 pricing applies. Costs estimated via aws_ |
Optimization tips
Common ways to reduce aws_ cost without changing the workload.
Use Fargate Spot for stateless and batch tasks
70%Spot is 70% cheaper than regular Fargate. Right for stateless workers, async job processors, CI runners, and any task that tolerates 2-minute eviction warnings.
Use Compute Savings Plans for steady Fargate workloads
27-52%Fargate is covered by Compute Savings Plans. A 1-year commitment cuts Fargate prices by 27%, 3-year by 52%. Better than reserved instances for variable task definitions.
Right-size CPU and memory requests
30-75% on overprovisioned tasksFargate bills by requested CPU and memory. A task requesting 2 vCPU + 4 GB but actually using 0.5 vCPU + 1 GB pays 4x what it needs. Profile and shrink.
EC2 launch type for high-utilization steady workloads
40-60% on high-utilization workloadsIf you can keep a cluster of nodes >70% utilized, EC2 launch type with reserved instances is significantly cheaper than Fargate. Crossover is workload-dependent.
FAQ
Fargate or EC2 launch type, which is cheaper?
Depends on utilization. EC2 launch type is cheaper per vCPU-hour but you pay for the whole instance regardless of how many tasks fit. Fargate is cheaper if your tasks don't fit cleanly into instance sizes or if you have spiky workloads. Crossover is typically around 50-70% sustained utilization.
Does c3x estimate Fargate based on task definition CPU/memory?
Yes. c3x reads the linked aws_
What about ECS on EC2 Spot?
EC2 launch type with Spot capacity providers offers ~70% savings on the underlying instances. The ECS service still pays for the EC2 instances, just at Spot prices. Configure via capacity_
Are load balancers included in ECS estimates?
No. Load balancers are separate resources (aws_
Related resources
More AWS resources
Further reading
- App Runner vs Fargate cost: managed simplicity or container control
App Runner and Fargate both run containers without managing servers, but they price and scale differently. App Runner bundles more of the operational layer at a per-resource rate, while Fargate gives finer control and can scale to zero more cheaply. Here is the cost comparison.
- AWS App Runner cost: active vs provisioned, and the idle charge
App Runner bills active compute (vCPU and memory) while serving requests and a lower provisioned charge for memory when idle. That idle floor matters for low-traffic services. Here is how the two rates work and when App Runner is worth it.
- AWS Batch cost: free service, you pay for the compute it runs
AWS Batch adds no charge of its own; you pay for the EC2, Fargate, or Spot compute your jobs run on. Compute environment choice and Spot are the big levers. Here is how to run batch workloads cheaply.
- AWS Batch on Spot: cutting batch compute cost up to 90 percent
AWS Batch schedules containerized batch jobs across compute you configure, and because most batch work is interruption-tolerant, running it on Spot can cut compute cost by up to 90 percent. Here is how to configure Batch for Spot savings without losing jobs to interruptions.
Estimate this resource in your own Terraform
Free, open source, no API key. C3X parses your Terraform and shows line-item cost for every resource, including aws_.