aws_ecs_task_definition cost estimation
A task definition is free. It declares CPU and memory for a container task, and those numbers set the Fargate cost when an ECS service runs the task.
An aws_ecs_task_definition is the blueprint for a container task: which images to run, and how much CPU and memory to reserve. Registering a task definition costs nothing. The cost is realized when an ECS service or a run-task call actually launches tasks from it.
On Fargate, the task definition is where the money is decided. Fargate bills per vCPU-hour and per GB-hour for the exact cpu and memory you declare, for as long as the task runs. A task with cpu = 1024 (1 vCPU) and memory = 2048 (2 GB) costs roughly $0.04/hour on Fargate, so one task running continuously is about $30/month, and a service running 10 of them is about $300/month. Over-declaring cpu or memory is the most common Fargate overspend, because you pay for the reservation whether the container uses it or not.
On EC2 launch type, the task definition's cpu and memory instead determine how many tasks pack onto your cluster instances, so the lever is bin-packing efficiency rather than a direct per-task charge.
c3x reads the cpu and memory from a task definition and, combined with the desired count on the ECS service, prices the Fargate cost before you deploy, which is the fastest way to catch an oversized task.
Terraform example
A minimal but realistic configuration that C3X can estimate.
resource "aws_ecs_task_definition" "api" {
family = "api"
requires_compatibilities = ["FARGATE"]
network_mode = "awsvpc"
cpu = 512 # 0.5 vCPU
memory = 1024 # 1 GB
container_definitions = jsonencode([
{
name = "api"
image = "123456789.dkr.ecr.us-east-1.amazonaws.com/api:latest"
essential = true
portMappings = [{ containerPort = 8080 }]
}
])
}Pricing dimensions
What you actually pay for when you provision aws_ecs_task_definition.
| Dimension | Unit | What's being charged |
|---|---|---|
| Task definition | free | Registering and storing revisions has no charge. $0 |
| Fargate vCPU | per vCPU-hour | The cpu you declare, billed while a task runs on Fargate. ~$0.04048/vCPU-hour |
| Fargate memory | per GB-hour | The memory you declare, billed while a task runs on Fargate. ~$0.004445/GB-hour |
Optimization tips
Common ways to reduce aws_ecs_task_definition cost without changing the workload.
Right-size cpu and memory
Often 30 to 50% on over-provisioned tasksFargate bills the exact reservation. Set cpu and memory to what the container actually uses, measured from CloudWatch, rather than rounding up out of caution.
Use Fargate Spot for stateless tasks
Up to 70% on eligible tasksStateless, interruption-tolerant tasks can run on Fargate Spot for a large discount by setting the capacity provider on the service.
Scale the service to demand
The task definition sets per-task cost; the service's desired count sets how many run. Scale in during quiet periods so you are not paying for idle tasks.
FAQ
Does an ECS task definition cost money?
No. Registering a task definition is free. You pay only when an ECS service or run-task launches tasks from it, at which point Fargate bills the declared cpu and memory per hour.
How is Fargate cost calculated from a task definition?
Fargate charges per vCPU-hour and per GB-hour for the exact cpu and memory in the definition, multiplied by how many tasks run and for how long. A 1 vCPU, 2 GB task running continuously is about $30/month.
What is the most common Fargate overspend?
Over-declaring cpu and memory. Fargate bills the reservation whether the container uses it or not, so oversized task definitions waste money on every running task.
Related resources
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_ecs_task_definition.