Skip to content
GKgkml.dev
← Learn AWS Cloud

Lesson 3 of 7 · 9 min

Compute: EC2, containers and serverless

Choose between instances, containers and functions on the axes that actually decide it — control, duration and idle cost.

The spectrum

OptionYou manageBills forFits
EC2OS, runtime, scaling, patchingInstance-hoursLegacy apps, full control, licensing constraints
ECS / EKS on EC2Cluster capacityInstance-hoursContainers where you want node control
FargateNothing below the taskvCPU and memory per secondContainers without capacity management
LambdaNothing below the functionRequests and GB-secondsEvent-driven work under 15 minutes

Choosing

Work down the list until something disqualifies an option. Does the job run longer than 15 minutes, or need a GPU, or hold state in memory across requests? Lambda is out. Do you need a specific kernel, a licence tied to hardware, or a persistent local disk? You are on EC2.

Otherwise the question is idle cost. Traffic that goes to zero favours serverless, because you pay nothing between requests. Steady 24/7 load favours instances with a commitment discount.

Purchasing options

On-Demand is the baseline: no commitment, highest rate. Savings Plans and Reserved Instances trade a one- or three-year commitment for a large discount, which is right for a steady baseline. Spot uses spare capacity at up to about 90% off but can be reclaimed with two minutes' notice.

Spot is safe when the work is interruption-tolerant and checkpointed. The way to reduce interruptions is to diversify across instance types and AZs — bidding higher does not help, because pricing has not been an auction since 2018.

Making Auto Scaling behave

Target tracking is the sensible default: name a metric and a target, and AWS adjusts capacity. But choose a metric that actually saturates — if the bottleneck is I/O concurrency rather than CPU, scaling on CPU reacts far too late.

The classic failure is instances launching and terminating in a loop, which almost always means the health check grace period is shorter than application startup. A warm pool or a golden AMI with dependencies pre-baked fixes slow starts properly.

Worth remembering

  • The real question is how much of the stack you want to own.
  • Lambda's 15-minute ceiling and per-invocation limits rule it out for long jobs.
  • Auto Scaling adds instances; load balancing distributes requests. They are different jobs.

Test it now

Compute selection and Auto Scaling behaviour are common medium questions.