How are Fargate and EC2 billed differently for ECS services?

ECS can run tasks on two kinds of capacity. With the Fargate launch type, AWS provisions and manages the underlying hosts, and you never see an instance. With the EC2 launch type, tasks are placed onto container instances in your account, which are EC2 instances running the ECS agent that you provision, patch, and scale yourself. ECS adds no orchestration fee for either, so the compute bill is the whole comparison.

The billing units differ. Fargate charges for the vCPU and memory requested in the task definition, from when the task starts pulling its image until it stops. Actual CPU usage does not change the price. EC2 charges for whole instances while they run, whether they host ten tasks or none. Any CPU or memory on an instance that no task has reserved is still billed, so with EC2, idle capacity costs you money directly.

Dimension Fargate EC2 launch type
Billing unit Task (requested vCPU + memory) Instance (full size)
Billed while Task is running Instance is running
Unreserved capacity Not billed Billed
Bin-packing responsibility AWS You
Host patching and AMIs AWS You

Steady workloads are where this difference decides the outcome. Bursty or short-lived jobs suit Fargate because you pay only while tasks exist. A service that runs the same task count around the clock gives you a predictable footprint, and you can pack that footprint tightly onto instances. If you pack it well, EC2's lower price per unit of capacity can win. If you leave instances half-empty, Fargate's per-task pricing usually comes out cheaper.

Why does utilization decide the Fargate vs EC2 cost break-even?

If you leave instances half-empty, Fargate's per-task pricing wins. You pay for the whole instance whether one task or eight are running on it. So the useful number is how much of each instance actually holds tasks, not the instance's hourly price.

Illustrative estimate (assumed numbers, not a benchmark). These are placeholders. Replace them with current prices for your region before drawing any conclusion.

  • Fargate: $0.040 per vCPU-hour and $0.0045 per GB-hour (assumed)
  • Task shape: 1 vCPU, 2 GB, so Fargate costs 0.040 + (2 × 0.0045) = $0.049 per task-hour
  • EC2 instance: 8 vCPU, 16 GB at $0.30/hour (assumed), which fits at most 8 tasks if you ignore agent and OS overhead

Define packing efficiency u as tasks placed divided by maximum tasks. The effective EC2 cost per task is:

EC2 per-task cost = instance price ÷ (max tasks × u)

Packing efficiency (u) Tasks on instance EC2 cost per task-hour Fargate cost per task-hour
100% 8 $0.0375 $0.049
75% 6 $0.050 $0.049
50% 4 $0.075 $0.049
25% 2 $0.150 $0.049

To find the break-even, set the two costs equal and solve for u:

u* = instance price ÷ (max tasks × Fargate per-task price) = 0.30 ÷ (8 × 0.049) ≈ 77%

With these inputs, EC2 is cheaper only if you keep instances more than about three-quarters full on average. That average has to hold across deploys, scaling events, and quiet hours, not only at peak. Below that level, the idle capacity you pay for erases EC2's lower price per unit of capacity.

What hidden capacity costs reduce EC2's advantage?

Before tasks get any of an instance's capacity, three costs take a share of it.

Per-instance reservations. The OS, the ECS agent, and any daemon tasks (log shippers, metrics agents, security scanners) run on every instance. ECS cannot schedule service tasks into that capacity, but you still pay for it. The share is largest on small instances, because the daemon footprint stays roughly the same whatever the instance size.

Fragmentation. Tasks have to fit in whole. If your tasks are memory-heavy and the instance family is CPU-heavy, one dimension fills up first and the other sits idle. A host with spare CPU and no spare memory can't take another task. That spare CPU is stranded.

Deployment headroom. Rolling deployments start new tasks before they stop old ones. You need spare room for the surge, or deploys stall. That room sits empty most of the time.

To fold these into the break-even, compute what fraction of each instance tasks can actually use:

usable fraction = (capacity − reserved − stranded) ÷ capacity × (1 − deploy headroom)

Illustrative estimate (assumed numbers, not a benchmark): a 4 vCPU instance, 0.25 vCPU reserved, 0.5 vCPU stranded, 10% deploy headroom: (4 − 0.25 − 0.5) ÷ 4 × 0.9 ≈ 73%. That ceiling is already below the roughly 75% the previous section said EC2 needs, before any quiet-hour idle time is counted.

Fargate has a smaller version of the same problem. Tasks must use a supported CPU/memory combination. A task that needs 1.2 vCPU is billed as 2 vCPU, so only 60% of what you pay for is used. The difference from EC2 is where the waste shows up. On Fargate it appears in each task definition, and you can reduce it by tuning task sizes. On EC2 it is spread across the fleet and harder to see.

ILLUSTRATIVE ESTIMATE (assumed inputs, not a benchmark)

EC2 HOST: 4 vCPU billed
+----------------------------+-------------+------------------------+
| OS + ECS agent + daemons   |  0.25 vCPU  | reserved, never usable |
+----------------------------+-------------+------------------------+
| stranded by fragmentation  |  0.50 vCPU  | memory fills first     |
+----------------------------+-------------+------------------------+
| rolling-deploy headroom    | ~0.33 vCPU  | 10% of the 3.25 left   |
+----------------------------+-------------+------------------------+
| service tasks              | ~2.92 vCPU  | usable by tasks        |
+----------------------------+-------------+------------------------+
              |
              v
 usable = (4 - 0.25 - 0.5) / 4 x 0.9 = ~73%
 below the ~75% EC2 needs; waste is spread across the fleet

FARGATE TASK: needs 1.2 vCPU
+----------------+          +---------------------------------------+
| requested      |  round   | billed: 2 vCPU (supported size)       |
| 1.2 vCPU       | -------> +-------------------+-------------------+
|                |    up    | used 1.2 vCPU     | unused 0.8 vCPU   |
+----------------+          +-------------------+-------------------+
                                      |
                                      v
 used / billed = 1.2 / 2 = 60%
 waste is visible per task definition; reduce it by tuning task size

Illustrative estimate: reservations, fragmentation, and deploy headroom cut a 4 vCPU EC2 host to about 73% usable capacity, while Fargate's rounding waste appears inside each task definition.

How do Savings Plans, commitments, and Spot shift the comparison?

Discounts exist on both sides, so the first rule is to compare like with like. Pricing on-demand Fargate against EC2 covered by Reserved Instances or a Savings Plan only measures the discount, not the launch type.

Option Fargate EC2 Main trade-off
Compute Savings Plans Yes Yes Hourly spend commitment, flexible across services
EC2 Instance Savings Plans No Yes Deeper discount, tied to one instance family and region
Reserved Instances No Yes Tied to instance attributes
Spot (Fargate Spot / EC2 Spot) Yes Yes Capacity can be reclaimed with a short notice

Compute Savings Plans cover both Fargate and EC2, so they lower both prices and leave the comparison mostly where it was. The commitments that apply only to EC2 give a larger discount because they lock you into one instance family. That works well if the workload stays the same size. It is a bet against the workload shrinking, being re-architected, or moving to Fargate.

Illustrative estimate (assumed numbers, not a benchmark):

  • Assume an EC2 Instance Savings Plan commitment of $10/hour.
  • Assume the same workload costs $16/hour on Fargate on-demand at full size.
  • The commitment is billed whether you use it or not.

The commitment stops paying off when:

usage fraction < commitment ÷ Fargate on-demand cost at full size

With these inputs, 10 ÷ 16 = 62.5%. If the service shrinks below about 62% of its committed size, Fargate on-demand would have been cheaper.

Spot can cut costs on both launch types, but tasks can be interrupted. A steady service needs to handle SIGTERM gracefully, drain connections within the notice window, and keep enough on-demand tasks running to hold its baseline when Spot capacity is reclaimed.

How can capacity providers control the headroom you pay for?

With an Auto Scaling group capacity provider and managed scaling enabled, ECS sizes the group from task demand. The target capacity setting, a percentage, is how you choose your headroom. At 100, ECS aims to run only as many instances as the placed tasks need, so you pay for almost no idle capacity, but new tasks may have to wait while instances boot. At 80, ECS keeps about a fifth of the group spare. Deployments and scale-outs then land immediately, and you pay for that buffer continuously. Managed termination protection stops scale-in from removing instances that still run tasks.

A capacity provider strategy splits a service's tasks across providers. Base sets how many tasks must run on one provider before any others are used, and only one provider in a strategy can have a base. Weight sets the ratio for every task above the base. A common steady-service pattern sets an on-demand ASG provider with a base covering the baseline, then adds a Spot ASG provider with a higher weight to absorb growth.

One constraint matters here. A single strategy cannot mix ASG providers with FARGATE or FARGATE_SPOT. To keep a baseline on EC2 and burst to Fargate, run two services behind the same target group and scale each one independently.

Both approaches make scaling events harder to reason about. Task placement depends on base, weight, instance warm-up time, and Spot availability all at once. During incidents, check which provider each task actually landed on.

# 1) On-demand ASG provider. targetCapacity=90 keeps roughly 10% spare instance capacity.
# Managed termination protection requires scale-in protection to be enabled on the ASG.
aws ecs create-capacity-provider \
  --name cp-ondemand \
  --auto-scaling-group-provider '{
    "autoScalingGroupArn": "arn:aws:autoscaling:us-east-1:123456789012:autoScalingGroup:11111111-2222-3333-4444-555555555555:autoScalingGroupName/ecs-ondemand",
    "managedScaling": {"status": "ENABLED", "targetCapacity": 90},
    "managedTerminationProtection": "ENABLED"
  }'

# 2) Spot ASG provider. targetCapacity=100 packs tightly, so burst tasks may wait for instance boot.
aws ecs create-capacity-provider \
  --name cp-spot \
  --auto-scaling-group-provider '{
    "autoScalingGroupArn": "arn:aws:autoscaling:us-east-1:123456789012:autoScalingGroup:66666666-7777-8888-9999-000000000000:autoScalingGroupName/ecs-spot",
    "managedScaling": {"status": "ENABLED", "targetCapacity": 100},
    "managedTerminationProtection": "ENABLED"
  }'

# 3) Attach both providers to the cluster. A strategy may not mix these with FARGATE or FARGATE_SPOT.
aws ecs put-cluster-capacity-providers \
  --cluster prod-web \
  --capacity-providers cp-ondemand cp-spot \
  --default-capacity-provider-strategy capacityProvider=cp-ondemand,weight=1

# 4) Mixed strategy. The first 4 tasks always go to on-demand (base, steady baseline).
# Tasks above the base split 1:3 between on-demand and Spot. Of 10 tasks, about 6 land on Spot.
aws ecs create-service \
  --cluster prod-web \
  --service-name web \
  --task-definition web:12 \
  --desired-count 10 \
  --capacity-provider-strategy \
      capacityProvider=cp-ondemand,base=4,weight=1 \
      capacityProvider=cp-spot,weight=3

# During incidents, check which provider each task actually landed on.
aws ecs describe-tasks --cluster prod-web \
  --tasks $(aws ecs list-tasks --cluster prod-web --service-name web --query 'taskArns[]' --output text) \
  --query 'tasks[].[taskArn,capacityProviderName]' --output table

This example creates two ASG capacity providers with different managed-scaling target capacities and runs a service that keeps a fixed on-demand base while weighting growth toward Spot. It finishes by listing which provider each task ran on.

What does running EC2 capacity cost in engineering time?

The EC2 savings from earlier sections are only real if you subtract the hours your team spends keeping the hosts healthy. Fargate absorbs that work; on EC2 it becomes a recurring line item that rarely appears in a cost spreadsheet.

The recurring tasks are predictable:

  • AMI patching: rebuilding or adopting updated ECS-optimized AMIs, rolling them through Auto Scaling groups, and verifying nothing regressed.
  • Instance draining: setting instances to DRAINING so tasks reschedule before termination, and chasing tasks that don't move cleanly.
  • ECS agent updates: keeping the container agent current, usually bundled with AMI rotation.
  • Scaling troubleshooting: diagnosing why tasks sit in PROVISIONING, why the ASG didn't scale out, or why bin-packing left capacity stranded.

To estimate the cost, log each task's hours for one or two months instead of guessing. Then use:

Monthly ops cost = Σ (hours per occurrence × occurrences per month) × loaded hourly rate

Illustrative estimate (assumed numbers, not a benchmark): Assume patching takes 4 hours per month, draining issues take 2, agent updates take 1, and scaling investigations take 3. That totals 10 hours. At an assumed loaded rate of $100/hour, the result is $1,000/month. Compare that figure with the compute savings you calculated for EC2.

Teams with mature automation will see a much smaller number. Automated AMI pipelines, lifecycle hooks, and well-tuned capacity providers push most of this work to near zero.

Fargate's savings in engineering time come with a trade-off. You get less visibility into the host. You can't SSH into the underlying host or run daemon-scheduled agents, so per-host monitoring and security tools must run as sidecars. Some low-level debugging also becomes slower or impossible.

How do you calculate your own Fargate vs EC2 break-even?

Treat the comparison as a model you rerun whenever prices, task shapes, or traffic change. Each input exists to keep one side from looking cheaper than it is.

  1. Record task shapes. For each service, note the vCPU and memory actually reserved in the task definition. Fargate bills only specific CPU/memory combinations, so round each task up to the nearest supported size. Otherwise you understate Fargate.
  2. Pull current prices for your region and architecture (x86 or Arm). Use Fargate's per-vCPU-hour and per-GB-hour rates and the on-demand rate for your candidate instance types. Rates differ by region and architecture, so prices from a blog post or another account's bill will skew the result.
  3. Estimate steady task counts from the baseline, not the peak, and add burst hours separately.
  4. Set a realistic packing efficiency. This is the share of instance CPU and memory that tasks actually reserve after daemon overhead, AZ spread, and deployment surge. Measure it from your cluster if you have one.
  5. Apply discount coverage separately for each side. Use the fraction of usage your commitments really cover, not the maximum discount rate.
  6. Price operational hours at a loaded engineering rate.

Then compare monthly totals:

  • Fargate = tasks × (vCPU × vCPU rate + GB × GB rate) × 730 × (1 − Fargate discount)
  • EC2 = ceil(total reserved vCPU ÷ packing efficiency ÷ vCPU per instance) × instance rate × 730 × (1 − EC2 discount) + EBS + ops hours × hourly rate

Run the EC2 formula a second time with memory in place of vCPU and keep the larger instance count. Finally, solve for the packing efficiency at which the two totals are equal. If your measured efficiency is not clearly above that value, EC2's savings are within your error margin.

import math

# Placeholder rates: replace with current prices for your region and architecture.
FARGATE_VCPU_HR = 0.040   # $ per vCPU-hour (placeholder)
FARGATE_GB_HR = 0.0045    # $ per GB-hour (placeholder)
INSTANCE_HR = 0.15        # $ per hour, candidate instance type (placeholder)
INSTANCE_VCPU, INSTANCE_GB = 4, 16
HOURS = 730               # hours per month

# Steady baseline. Task size is already rounded up to a supported Fargate combination.
tasks, task_vcpu, task_gb = 60, 1.0, 2.0
# Effective discount = fraction of usage covered x discount rate, not the headline rate.
fargate_discount = 0.50 * 0.40
ec2_discount = 0.70 * 0.45
ebs_monthly = 40.0                 # root and data volumes for the cluster
ops_hours, ops_rate = 4, 100.0     # monthly EC2 upkeep at a loaded hourly rate

def fargate_total():
    per_task_hr = task_vcpu * FARGATE_VCPU_HR + task_gb * FARGATE_GB_HR
    return tasks * per_task_hr * HOURS * (1 - fargate_discount)

def ec2_total(eff):
    # Size the cluster on both CPU and memory, then keep whichever needs more instances.
    by_cpu = math.ceil(tasks * task_vcpu / eff / INSTANCE_VCPU)
    by_mem = math.ceil(tasks * task_gb / eff / INSTANCE_GB)
    n = max(by_cpu, by_mem)
    return n * INSTANCE_HR * HOURS * (1 - ec2_discount) + ebs_monthly + ops_hours * ops_rate

fg = fargate_total()
print(f"Fargate: ${fg:,.0f}/month")
for pct in (50, 65, 80, 90):
    print(f"EC2 at {pct}% packing: ${ec2_total(pct / 100):,.0f}/month")

# EC2 cost falls as packing improves, so the first efficiency where EC2 <= Fargate is break-even.
break_even = next((p for p in range(30, 101) if ec2_total(p / 100) <= fg), None)
print(f"Break-even packing: {break_even}%" if break_even else "EC2 never cheaper at these inputs")

A Python model that prices Fargate and EC2 from your own task shapes, placeholder rates, effective discount coverage, and ops time, then scans packing efficiency to find the break-even point.

When should you choose EC2, Fargate, or a mix?

Choose EC2 when your tasks are steady and similar enough in shape to pack densely, and when you already have automation for AMI updates, draining, and scaling. EC2 is also the only option when you need GPUs, a specific instance family, instance-store NVMe disks, or host-level changes such as kernel parameters or custom daemons. Avoid it if nobody owns the hosts. Unpatched instances and stuck drains cost more than the per-vCPU discount saves.

Choose Fargate when you lack EC2 automation, when task sizes vary widely, or when your measured packing efficiency sits near or below the break-even. Fargate bills each task at its own size, so oddly shaped tasks waste nothing at the host level. Avoid it for large, flat fleets where you have proven high utilization, because there you pay its premium on every hour.

A mix fits services with a predictable floor and unpredictable peaks. Use a capacity provider strategy with a base on an EC2 provider sized to the floor, and a weight that sends overflow tasks to Fargate or Fargate Spot. The packed EC2 hosts carry the steady load, and Fargate absorbs bursts without you holding idle headroom.

Option Best fit Avoid when
EC2 Dense, steady, uniform tasks; GPUs, instance store, host tuning No one owns AMIs, patching, or drains
Fargate Uneven task shapes, low utilization, small platform team Large flat fleets with proven high packing
Mixed Steady base plus bursts Load has no stable floor

Re-run the calculation when any of these change:

  • Task sizes
  • Traffic shape
  • Commitment coverage
  • Measured packing efficiency
  • The number of people available to maintain hosts

How OneEnv can help

Disclosure: OneEnv is the product behind this blog.

OneEnv (oneenv.io) is a workspace-based governance platform for the things services share — environment variables, database structure, API routes and validation rules. A change to a shared value is staged on a branch, reviewed once, and then every affected service explicitly approves or rejects it before it goes live, so you can see who a change touches before it ships instead of finding out in production.

Applied to fargate vs ec2 cost, this is where it helps:

Saves time

  • Every service that inherits a shared value is listed in one place, so nobody searches repos and chats to find out who is affected.
  • One review per branch replaces coordinating each team separately; each service still keeps its own approve/reject.
  • Adding or removing a column goes through one review with the inheriting services listed, instead of ad-hoc messages to each team.

Saves cost

  • Fewer production incidents and rollbacks caused by a shared value, route or column changing under a consumer unannounced.
  • Less duplicated configuration to maintain: one shared definition inherited by many services.
  • Services that depend on a column get the chance to object before it disappears, avoiding emergency fixes.
  • OneEnv has a free plan (1 workspace, unlimited services and members, full governance), so trying it costs nothing.

These are qualitative benefits, not measured results — how much you save depends on how many services share the value.

Want to try it? Start at oneenv.io.