Arkinu
AWS service comparison

Amazon EC2 vs AWS Fargate: differences and when to use each

Amazon EC2
AWS Fargate

Often confused on the examQuestions tend to offer one as a distractor for the other: look for the phrase in the scenario that tips the balance.

Compute

Amazon EC2

On-demand, scalable compute capacity in the form of virtual servers (instances), whose instance type determines the combination of CPU, memory, networking, and storage. It lets you launch as many servers as you need, configure their networking and security, and scale capacity up or down with the load.

Exam phrases that point here

  • «the workload tolerates interruptions and the goal is the lowest possible cost»

    Spot Instances use spare EC2 capacity at a steep discount compared with On-Demand, in exchange for AWS being able to reclaim them with advance notice. They fit fault-tolerant or resumable workloads.

    When not: If the workload cannot be interrupted (a production database, an application with state on the instance), Spot is not the answer: think of On-Demand or, if usage is steady, Savings Plans or Reserved Instances.

  • «steady, predictable usage for one or three years, at the lowest cost»

    Savings Plans and Reserved Instances give a discount in exchange for a 1- or 3-year commitment: Savings Plans commit to an hourly spend, while Reserved Instances commit to an instance configuration.

    When not: If the scenario also requires guaranteed capacity in an Availability Zone, Savings Plans do not reserve it: you need a zonal Reserved Instance or an On-Demand Capacity Reservation. If the workload is short-lived or unpredictable, On-Demand.

  • «reuse existing per-socket or per-core software licenses»

    Dedicated Hosts give you an entire physical server for your instances, which lets you use server-bound licenses.

    When not: If the requirement is only compliance (hardware that is not shared with other customers) with no need to control the physical server for licensing, Dedicated Instances also fit.

  • «the lowest possible network latency between the instances of an HPC cluster»

    A cluster placement group launches instances close together so they communicate with low latency; with Elastic Fabric Adapter (EFA), tightly coupled HPC applications gain even more.

    When not: If the priority is that a hardware failure does not take down several instances at once, the goal is to spread them out (spread placement group, multiple Availability Zones), not to put them close together.

  • «the application takes a long time to start and must come back quickly with its in-memory state preserved»

    When an instance hibernates, the contents of RAM are saved to the EBS root volume and restored when it starts again, so the application resumes where it left off.

    When not: Hibernation must be enabled when the instance is launched and requires an encrypted EBS root volume. If the goal is for data to survive instance termination, the solution is to store it in EBS, EFS, or S3, not to hibernate.

  • «applications on EC2 must access Amazon S3 without storing access keys on the instance»

    An IAM role attached to the instance (through an instance profile) delivers temporary credentials to the application, and they are renewed automatically.

    When not: If the caller is not an instance but end users of a mobile or web application, think of Amazon Cognito; and if the problem is storing database passwords, think of AWS Secrets Manager.

Often paired with

  • Amazon EBS
  • Elastic Load Balancing (ELB)
  • Amazon EC2 Auto Scaling
Study Amazon EC2 →

Serverless

AWS Fargate

Technology for running containers with Amazon ECS or Amazon EKS without managing servers or clusters of Amazon EC2 instances. You define the CPU, memory, networking, and permissions for each task or pod, and no longer have to choose server types or scale the cluster.

Exam phrases that point here

  • «run containers without provisioning or managing servers or EC2 instances»

    With Fargate you define the CPU, memory, networking, and permissions of each task (ECS) or pod (EKS), and AWS provides the capacity: there are no instance types to choose, no cluster to scale, and no node operating system to patch.

    When not: If the scenario requires GPUs, control over the instance (your own AMI, SSH access to the node), or Kubernetes DaemonSets, you use ECS or EKS on EC2 instances. If it is not about containers but about short code that reacts to events, think of AWS Lambda.

  • «interruption-tolerant container tasks at the lowest possible cost»

    Fargate Spot runs ECS tasks on spare capacity at a discount compared with the regular Fargate price. AWS can reclaim it with a two-minute warning.

    When not: If the tasks cannot be interrupted, use regular Fargate (and, if usage is steady, Savings Plans). Also, Amazon EKS does not support Fargate Spot: it applies only to Amazon ECS.

  • «each workload must run in isolation, without sharing a kernel, CPU, or memory with others»

    In Fargate each task or pod runs in its own single-use compute environment, with its own kernel, resources, and network interface, separated from the others by a virtualization boundary.

    When not: If the requirement is dedicated physical hardware (for example, for per-socket or per-core licenses), Fargate does not provide it: think of Amazon EC2 Dedicated Hosts.

  • «containers on Fargate need persistent, shared storage»

    A task's or pod's ephemeral storage is erased when it stops, so anything that must persist or be shared across containers is stored in Amazon EFS, which Fargate can mount.

    When not: If the data is needed only while the task is alive (temporary files), ephemeral storage is enough. If it is object data accessed through an API, Amazon S3. On EKS with Fargate, you cannot mount Amazon EBS volumes in pods.

  • «stop managing and patching the nodes of a Kubernetes cluster»

    With Amazon EKS and a Fargate profile, the pods that match the profile run on Fargate: there are no EC2 nodes to create, update, or scale.

    When not: Pods on Fargate do not support DaemonSets, privileged containers, GPUs, or public subnets. If the workload needs any of those, you use EC2 nodes (for example, managed node groups).

Study AWS Fargate →