AWS fundamentals path · Compute · Topic 8 of 18

Compute choices: EC2, ECS, EKS and Fargate

Not started

AWS offers a spectrum of compute, from raw virtual machines to functions that exist only while they run. The further along you go, the less you manage and the less you control. **EC2** gives you instances. **ECS** and **EKS** schedule containers onto capacity, which can be EC2 instances you manage or **Fargate**, where AWS provides an isolated environment per task or pod. **Lambda** (the next topic) runs functions per request or event.

Why it matters: Choosing between instances, containers and functions decides what you patch, how you scale, how you pay and what fails at 3 a.m.

  1. 1EC2 is a virtual machine

    You choose the instance type, image and disks, and you own everything from the operating system up.

  2. 2ECS and EKS schedule containers

    ECS is AWS's own orchestrator; EKS runs upstream Kubernetes with a managed control plane. Both place tasks or pods on capacity you choose.

  3. 3Fargate removes the hosts

    With Fargate you ask for vCPU and memory per task or pod, and AWS runs it in an isolated environment with no instances to manage.

  4. 4Auto Scaling groups replace what dies

    Instances should be cattle: launched from a template by an Auto Scaling group that keeps the count right across zones.

1

How it works

The explanation, with examples you can run.

What you own

EC2ECS or EKS on EC2ECS or EKS on FargateLambda
OS patchingYouYou (the nodes)AWSAWS
Scaling hostsAuto Scaling groupAuto Scaling group or KarpenterNoneNone
Unit you pay forInstance-hoursInstance-hoursvCPU and memory per secondRequests and GB-seconds
Longest runUnlimitedUnlimitedUnlimited15 minutes per invocation
ControlEverything (kernel, GPUs, disks)MostLess (no daemons on the host, fewer instance choices)Least

EC2 done properly

An instance is a launch template (image, instance type, security groups, IAM instance profile, user data) brought to life by an Auto Scaling group that spans several zones. The group replaces instances that fail health checks, scales on metrics, and rolls out a new template gradually with instance refresh. Keep no important state on the instance itself, so replacing it is routine rather than an incident. Instance metadata (IMDS) should be set to require IMDSv2 tokens, which blocks a class of server-side request forgery attacks that stole role credentials from IMDSv1.

Pricing models matter as much as instance types: on-demand for flexibility, Savings Plans or reserved capacity for a steady baseline, and Spot for interruptible work at a deep discount, with a two-minute warning before AWS reclaims the capacity.

Containers: ECS or EKS

  • ECS is simpler and AWS-specific: task definitions, services, and deep integration with load balancers, IAM task roles and CloudWatch. There is no control plane to pay for or upgrade.
  • EKS is Kubernetes. You get the portable API, its ecosystem (Helm, operators, Karpenter) and its complexity; AWS runs the control plane for an hourly fee, and you upgrade Kubernetes versions on its schedule.

Both run on EC2 nodes or on Fargate. Fargate removes node management and gives each task its own kernel boundary, at a higher price per vCPU and with some limits (no privileged containers or host daemons). A common mix is Fargate for most services and EC2 node groups for GPU, very large or cost-sensitive steady workloads.

Failure modes to plan for

  • One zone, one instance: put capacity in at least two zones and size so that losing one still leaves enough.
  • Capacity shortages: a specific instance type can run out in a zone. Allow several types (instance type flexibility) in groups and node pools.
  • Image drift: instances that were patched by hand differ from the template; bake images instead and replace instances.
2

Check yourself

3 questions. Get them all right to finish this topic.

  1. 1.Your team wants to run containers without managing or patching any EC2 instances. Which option fits?
  2. 2.Why put even a single EC2 instance in an Auto Scaling group?
  3. 3.Spot capacity is offered at a large discount. What is the catch?

0 of 3 right so far. Get all three to finish this topic.