Compute Strategy: EC2 vs. Containers vs. Lambda

Mastering the SAA-C03 Decision-Making Process

Study Guide: Choosing the Right Compute

In the AWS Certified Solutions Architect – Associate exam, you will frequently be asked to select a compute service based on specific constraints like cost, management overhead, and architectural flexibility. The goal is to find the “optimal” fit rather than just a “working” fit.

The Housing Analogy:
  • EC2 (Virtual Machines): Like buying a house. You are responsible for the plumbing, electricity, and maintenance, but you have total control over every room.
  • Containers (ECS/EKS/Fargate): Like renting an apartment. The building (OS/Kernel) is shared, but your unit is isolated and portable.
  • Lambda (Serverless): Like staying in a hotel. You show up, use the room, and leave. You don’t care how the hotel is built; you just pay for the time you are there.

Core Concepts & The Well-Architected Framework

When choosing compute, we evaluate through three primary pillars:

  1. Operational Excellence: Serverless (Lambda) wins here as AWS manages the underlying infrastructure, patching, and scaling.
  2. Performance Efficiency: Containers (Fargate) provide rapid scaling without managing EC2 instances. EC2 is preferred for specialized hardware needs (GPUs, High Memory).
  3. Cost Optimization: Lambda is “Pay-per-use” (scales to zero). EC2 and Containers (EC2 Launch Type) require paying for idle capacity unless managed via Auto Scaling.

Comparison Table: Compute Variants

Feature Amazon EC2 AWS Fargate (Containers) AWS Lambda
Management Full Control (OS level) Serverless Containers Fully Managed (Code only)
Scaling Speed Minutes (Instance Boot) Seconds Milliseconds
Max Duration Unlimited Unlimited 15 Minutes
Billing Model Per Second (Instance Type) Per vCPU/RAM per second Per Request / Duration

Scenario-Based Decision Matrix

  • IF the application is a legacy monolith that requires specific OS kernels or 24/7 uptime ➔ USE EC2.
  • IF you need to run microservices with consistent traffic and want to avoid managing VMs ➔ USE ECS/EKS with Fargate.
  • IF you have an event-driven task (e.g., S3 file upload trigger) that runs for less than 15 mins ➔ USE Lambda.
  • IF you have high-performance computing (HPC) requiring low-latency networking ➔ USE EC2 (Cluster Placement Groups).

Exam Tips: Golden Nuggets

  • Avoid the “Over-Provisioning” Distractor: If the exam mentions “minimal management” and “scaling to zero,” Lambda is almost always the answer.
  • EKS vs. ECS: Choose EKS if the scenario mentions Kubernetes compatibility or migrating from an on-premises K8s cluster.
  • Fargate is Key: In container questions, Fargate is the “Serverless” option for ECS/EKS. Use it to eliminate “managing EC2 clusters.”
  • Long-running Batch Jobs: If a job takes 20 minutes, Lambda is NOT an option. Use EC2 or ECS.
New Request Duration? Lambda (< 15m) Control? EC2 (Full OS) ECS/EKS (Portability)

Key Services

  • Lambda: Code execution.
  • ECS: Opinionated containers.
  • EKS: Managed Kubernetes.
  • Fargate: Serverless compute for containers.

Common Pitfalls

  • Using Lambda for heavy video processing (>15m).
  • Choosing EC2 for simple web APIs (Management heavy).
  • Ignoring “Cold Starts” in Lambda for latency-critical apps.

Quick Patterns

  • Microservices: ECS + Fargate.
  • Legacy Apps: EC2 + Auto Scaling.
  • Data Triggers: S3 + Lambda + DynamoDB.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top