Comparison Guides

Fargate vs EC2: Where Should Your Containers Run on AWS?

Same containers, same orchestrator. The difference is who owns the machines underneath, and how you pay for them.

Updated

Pick AWS Fargate if you want no servers to look after: you size each task or pod, AWS runs it in its own isolated environment and patches what's underneath, and you pay per second for the vCPU, memory and storage you asked for. Pick Amazon EC2 if you need what Fargate doesn't offer (GPUs, privileged containers, DaemonSets on EKS, host networking, a custom AMI), or if you run enough steady load that packing many containers onto instances you choose, with Spot or Savings Plans, beats paying for each task on its own. Between the two sit ECS Managed Instances and EKS Auto Mode: EC2 instances that AWS picks, patches and replaces for you, for a per-instance fee.

At a glance

AWS Fargate and Amazon EC2 side by side as compute for ECS and EKS
AWS FargateAmazon EC2
What you manageTask or pod size, networking, IAMAll of that, plus the instances: AMIs, patching, scaling, draining
What you pay forRequested vCPU, memory and extra ephemeral storage, per second (1-minute minimum)Whole instances, per second, whether or not your containers fill them
IsolationEach task or pod gets its own kernel, CPU, memory and network interfaceContainers share the instance's kernel
SizesFixed vCPU and memory combinations, starting at 0.25 vCPUAny instance type, including GPU, high-memory and storage-optimized
SpotFargate Spot on ECS (up to 70% off, per AWS); not on EKSEC2 Spot Instances on ECS and EKS
Savings PlansCompute Savings Plans applyCompute and EC2 Instance Savings Plans, Reserved Instances
Arm (Graviton)ECS onlyECS and EKS
GPUsNot supportedYes, on GPU instance types
Privileged containersNoYes
DaemonSets (EKS)No; run agents as sidecarsYes
Image cachingEvery new task or pod pulls its imageImages already on the instance start faster
PatchingAWS replaces tasks onto patched platform revisionsYou roll new AMIs onto your instances (or let Managed Instances or Auto Mode do it)

What you are actually choosing

On AWS, the orchestrator and the compute are two separate decisions. ECS or EKS decides how you describe and schedule containers. Fargate or EC2 decides what they run on.

AWS Fargate is serverless compute for containers. On ECS you set CPU and memory in the task definition; on EKS you set requests on the pod and a Fargate profile picks which pods go there. AWS starts each task or pod in its own isolated environment, with its own kernel and network interface, and you never see a server.

Amazon EC2 means your containers run on instances in your account. On ECS that is usually an Auto Scaling group running the ECS-optimized AMI, attached to the cluster through a capacity provider. On EKS it is managed node groups, self-managed nodes or Karpenter. The scheduler packs many containers onto each instance, and the instances are yours to size, patch and replace.

Both run the same images from the same registries, in your VPC, with the same IAM roles for your workloads. Most teams can move a service from one to the other without rebuilding it.

How each one is priced

Fargate bills the vCPU and memory you request, per second with a one-minute minimum, from the moment the image starts downloading until the task or pod stops. Every task and pod gets 20 GB of ephemeral storage included; you pay only for more. Arm (Graviton) tasks on ECS cost less per vCPU and GB than x86. In AWS's own example for US East (N. Virginia), Linux/x86 Fargate costs $0.000011244 per vCPU-second and $0.000001235 per GB-second, so a task with 1 vCPU and 2 GB running all month (730 hours) comes to about $36 at those rates. Rates differ by region and change over time: check Fargate pricing for yours.

EC2 bills the instance, at the price of its type and purchase option, whether your containers use all of it or a tenth. Packing several services onto one instance is how EC2 gets cheaper than Fargate; leaving instances half empty is how it gets more expensive. ECS and EKS add no charge for EC2 capacity beyond EKS's cluster fee, which applies either way.

A few details change the sums:

  • On EKS, Fargate rounds up. It adds 256 MB to each pod's memory for the kubelet, kube-proxy and containerd, then rounds up to the nearest valid size. AWS's example: a pod requesting 1 vCPU and 8 GB is billed as 2 vCPU and 9 GB. Check a pod's CapacityProvisioned annotation to see what you pay for.
  • Requests become the bill. On Fargate, an overstated request is paid for directly. On EC2 it wastes room on the instance instead. Either way, set requests from what services actually use.
  • Discounts work differently. Compute Savings Plans cover Fargate (AWS quotes up to 50% off for a one- or three-year commitment). Fargate Spot on ECS runs interruption-tolerant tasks at up to 70% off with a two-minute warning; EKS doesn't support Fargate Spot. On EC2 you can mix Spot Instances, Reserved Instances and Savings Plans.
  • The rest of the bill is the same. Load balancers, NAT gateways, logs, data transfer and public IPv4 addresses cost the same whichever compute you pick.

For one or two small services that idle much of the day, Fargate is usually cheaper than an instance that sits there. For many services with steady load, well-packed EC2 usually wins on the invoice. Whether it wins once you count the engineering time is the question in the total cost of running Kubernetes on a managed platform vs self-hosted EKS.

What you have to operate on each

On Fargate there is no instance to patch. AWS rolls out new platform revisions with kernel and runtime fixes; new tasks always start on the latest one, and AWS retires tasks still running on an old revision. On ECS, a service replaces its retired tasks on its own (you get notice through AWS Health, 7 days by default or 14 if you set it); standalone tasks started with RunTask or a schedule are stopped and not replaced, so anything long-running belongs in a service. On EKS, AWS patches Fargate pods by evicting them, so PodDisruptionBudgets matter.

On EC2 you own the instances:

  • AMIs and patching. Roll new ECS-optimized or EKS-optimized AMIs onto your instances, draining containers off each old one first.
  • Scaling. ECS capacity providers with managed scaling, or Cluster Autoscaler or Karpenter on EKS, to add instances when containers don't fit and remove them when they are idle.
  • Instance types and packing. Choose sizes that fit your services, and keep an eye on how full they are.
  • Agents. The ECS container agent or the kubelet and node add-ons, kept compatible with the cluster. On EKS this is part of every cluster upgrade.

That is a recurring job. On a team without a DevOps engineer, it is the main argument for Fargate, or for the managed EC2 options below.

What Fargate can't do

Check this list before you commit, since any one of these sends a workload to EC2:

  • No GPUs. ECS lists the task definition's gpu parameter as not valid on Fargate, and EKS states that GPUs aren't available on Fargate.
  • No privileged containers. On ECS, the only Linux capability you can add is CAP_SYS_PTRACE. Security and network agents that need more won't run.
  • No DaemonSets on EKS. Log shippers and monitoring agents have to run as sidecars in each pod. hostPort and hostNetwork aren't allowed either.
  • One pod per Fargate node on EKS. Each pod is billed and sized on its own; pods can't burst into spare capacity on a shared node.
  • Storage on EKS. Fargate pods can mount EFS but not EBS volumes. ECS tasks on Fargate can use both.
  • Networking on EKS. Fargate pods run only in private subnets, load balancers must use IP targets, and the instance metadata service isn't available, so pods get IAM credentials through IAM roles for service accounts.
  • Fixed sizes. Tasks and pods come in set vCPU and memory combinations, listed in the ECS and EKS docs below; a workload that doesn't fit one of them belongs on EC2.
  • Architecture and OS. Arm and Windows on Fargate are ECS-only.
  • Startup time. Each task or pod pulls its image fresh. On ECS, a Seekable OCI (SOCI) index in Amazon ECR lets large images start before they have finished downloading.

Choose Fargate when

  • Nobody on the team wants to own instances, AMIs or node scaling.
  • You run a handful of stateless services, workers or scheduled jobs whose sizes fit Fargate's combinations.
  • Load is spiky or low: services that scale to a few copies at night, or jobs that run for minutes a day.
  • You want each workload isolated from the others at the kernel level without running a cluster per customer.
  • On ECS, you have interruption-tolerant work (queue consumers, batch jobs) that can use Fargate Spot.

Choose EC2 when

  • You need GPUs, privileged containers, specific instance types, a custom AMI or host-level access.
  • You run on EKS and rely on DaemonSets, EBS-backed StatefulSets or Spot capacity.
  • You run many services with steady load and can keep instances well packed. See running multiple services on one cluster cheaply.
  • Your services are large or bursty enough that sharing an instance's headroom beats paying for each task's peak.
  • Your images are big and startup time matters, and keeping them cached on instances helps.

The middle ground: EC2 that AWS runs for you

Both orchestrators now offer EC2 capacity without the instance work:

  • ECS Managed Instances. AWS picks cost-effective EC2 instances for your tasks (or ones matching attributes you set, including GPUs), places several tasks on each, patches them, and drains and replaces every instance within 14 days. Privileged Linux capabilities are available if you turn them on. There is no SSH and no custom AMI. Existing Fargate task definitions on platform version 1.4.0 work as they are. You pay the EC2 price plus a management fee per instance; see ECS pricing for the rates.
  • EKS Auto Mode. The same idea for Kubernetes: AWS runs Karpenter, the nodes and the core add-ons, and charges a per-instance fee on top of EC2. Spot and Graviton work through your own NodePools. We cover it in EKS Auto Mode explained.

Both bill whole instances, so packing matters as it does on plain EC2, and containers on the same instance share its kernel; ECS Managed Instances can be set to run each task on its own instance when you need that isolation. If Fargate's limits are what push you off it, start here before taking on EC2 yourself.

You don't have to pick one for everything

One cluster can use both. On ECS, each service names its capacity provider strategy, so web services can run on Fargate, queue workers on Fargate Spot and a GPU job on EC2. A single strategy can't mix Fargate with EC2 Auto Scaling groups or Managed Instances, but different services in the same cluster can use different ones. On EKS, Fargate profiles send pods that match a namespace and labels to Fargate, and everything else lands on your nodes.

A common path for a small team: start everything on Fargate, move a workload to EC2 or a managed option only when it hits a limit or its bill grows large enough to be worth packing, and keep the deploy pipeline unaware of which one it lands on. A deployment pipeline that only changes the image tag keeps that move cheap.

Questions

Is Fargate more expensive than EC2?
Per vCPU and GB it usually costs more than the same capacity on a well-used EC2 instance, but you pay only for what each task or pod requests, by the second. For small or spiky workloads, or instances that would sit half empty, Fargate often comes out cheaper. Compare AWS's Fargate and EC2 pricing pages for your region and instance sizes.
Can I use Fargate Spot on EKS?
No. AWS states that Amazon EKS doesn't support Fargate Spot. On EKS, use EC2 Spot Instances through managed node groups, Karpenter or an Auto Mode NodePool.
Does Fargate support GPUs?
No. ECS lists the gpu task definition parameter as not valid on Fargate, and EKS states GPUs aren't available on Fargate. Run GPU workloads on EC2, ECS Managed Instances or EKS Auto Mode.
Do Savings Plans apply to Fargate?
Yes. Compute Savings Plans cover Fargate usage on both ECS and EKS. AWS quotes savings of up to 50% for a one- or three-year commitment.
Can I SSH into a Fargate task?
No, there is no host to log in to. On ECS, use ECS Exec to open a shell in a running container; on EKS, use kubectl exec.
Can I move a service from Fargate to EC2 later?
Yes. The image doesn't change. On ECS you add EC2 to the task definition's compatibilities and switch the service's capacity provider; on EKS you change or remove the Fargate profile that matches the pod. Move one service at a time.

Sources

  1. AWS Fargate pricing

    Billing model, sizes, Fargate Spot, Savings Plans and the US East example rates.

  2. Amazon ECS pricing

    EC2 and ECS Managed Instances charges.

  3. Amazon ECS: Architect for AWS Fargate for Amazon ECS
  4. Amazon ECS: Task definition differences for Fargate

    Unsupported parameters, sizes, storage, SOCI.

  5. Amazon ECS: Task retirement and maintenance for AWS Fargate
  6. Amazon ECS: Architect for Amazon ECS Managed Instances
  7. Amazon EKS: Simplify compute management with AWS Fargate

    Fargate considerations and comparison table on EKS.

  8. Amazon EKS: Understand Fargate Pod configuration details

    Pod sizing, the 256 MB overhead, storage.

← All guides