Skip to main content
EC2 Instance Families

Module Overview

Estimated Time: 4-5 hours | Difficulty: Intermediate | Prerequisites: Core Concepts
This module covers all AWS compute services in depth. The core decision you will face on every project: how much operational overhead are you willing to trade for how much control? EC2 gives you the keys to the entire machine but you own every patch and scaling decision. Lambda takes all of that away but limits you to 15-minute executions and specific runtimes. ECS and EKS sit in the middle. You’ll learn when to use each service, how to optimize for cost and performance, and real-world architecture patterns. What You’ll Learn:
  • EC2 instance types, AMIs, and advanced configurations
  • Lambda functions for serverless computing
  • Container orchestration with ECS and EKS
  • Auto Scaling strategies for elasticity
  • Cost optimization techniques for compute

Compute Service Selection Guide

Choose the right compute service for your workload:

EC2 (Elastic Compute Cloud)

Virtual servers in the cloud. The most fundamental and flexible AWS compute service. EC2 is the “you can build anything” option — it gives you a full virtual machine with your choice of OS, and you can install any software that runs on Linux or Windows. The trade-off is that you are responsible for patching, scaling, and availability. Despite the rise of serverless, EC2 still runs the majority of production workloads on AWS because many applications need persistent state, specific kernel configurations, or GPU hardware that higher-level services cannot provide.

Instance Type Deep Dive

AWS offers 500+ instance types optimized for different workloads:

Instance Naming Convention

Pro Tip: Use Graviton (ARM) instances (m7g, c7g, r7g) for 40% better price/performance on compatible workloads. Most applications (Python, Node.js, Go, Java, containerized apps) work without modification. The main exceptions are software with x86 assembly optimizations or Windows-only binaries. If your application runs in a container, testing on Graviton is as simple as building a multi-arch image.

T-Series Burstable Instances

T-series instances use CPU credits for burstable performance:

AMI (Amazon Machine Image)

AMIs are templates containing OS, application server, and applications.

EC2 Instance Metadata Service (IMDS)

Access instance info from within the instance:

Lambda (Serverless Functions)

Run code without provisioning servers. Pay only for compute time used. Lambda is the opposite end of the spectrum from EC2: you give up control of the operating system, runtime environment, and scaling decisions, and in return AWS handles all of that for you. The result is that your infrastructure cost drops to zero when nobody is using your application — something that is impossible with EC2 instances that charge by the hour whether they are serving traffic or sitting idle.
Lambda Event-Driven Architecture

Lambda Architecture

Lambda Function Best Practices

Lambda Limits and Quotas

Lambda with Container Images


ECS (Elastic Container Service)

AWS-native container orchestration for Docker containers.

ECS Architecture Deep Dive

Task Definition Example


Auto Scaling

Automatically adjust compute capacity to match demand.

Auto Scaling Strategies

Auto Scaling Configuration (Terraform)


Cost Optimization

Compute Cost Strategies


🎯 Interview Questions

Lambda is better when:
  • Event-driven, short-running tasks (< 15 min)
  • Unpredictable or spiky traffic
  • You want zero server management
  • Cost matters more than consistent latency
EC2 is better when:
  • Long-running processes
  • Need specific OS/hardware (GPUs)
  • Consistent, predictable traffic
  • Cost optimization with Reserved Instances
  • Need persistent connections (WebSockets)
Strategies:
  1. Provisioned Concurrency - Pre-warm containers
  2. Smaller packages - Reduce initialization time
  3. Initialize outside handler - SDK clients, DB connections
  4. Use lighter runtimes - Go, Python, Node.js
  5. SnapStart for Java - Checkpoint/restore
  6. Keep functions warm - Scheduled pings (not ideal)
Code pattern:
Choose ECS when:
  • AWS-native, simpler setup
  • Smaller team without K8s expertise
  • Tighter AWS integration needed
  • Lower operational overhead
Choose EKS when:
  • Multi-cloud strategy
  • Team has Kubernetes expertise
  • Need K8s ecosystem (Helm, operators)
  • Complex microservices architectures
  • Portability is important
Cost Note: EKS adds 0.10/hourpercluster( 0.10/hour per cluster (~72/month)
Multi-layered approach:
  1. Predictive Scaling: Scale up before known peaks (Black Friday)
  2. Target Tracking: Maintain 50% CPU average
  3. Step Scaling: Add extra capacity for sudden spikes
Configuration:
  • Minimum: 4 instances (2 per AZ)
  • Desired: 6 instances (normal load)
  • Maximum: 50 instances (peak capacity)
Policies:
  • Target tracking: CPU at 50%
  • Step: +4 if CPU > 80% for 2 min
  • Scheduled: Scale to 20 at 8 AM, 10 at 10 PM
  • Predictive: Enable for daily patterns
Cool-downs:
  • Scale-out: 60 seconds
  • Scale-in: 300 seconds (avoid thrashing)
Framework (in order of impact):
  1. Right-size (15-30% savings)
    • Use Compute Optimizer
    • Monitor actual utilization
  2. Purchase options (30-72% savings)
    • Reserved for baseline (60-70% of capacity)
    • Spot for stateless/batch
    • Savings Plans for flexibility
  3. Instance selection (20-40% savings)
    • Graviton (ARM) for compatible workloads
    • Latest generation (m7 vs m5)
  4. Shutdown automation
    • Stop dev/test outside hours
    • Auto-scaling to zero when possible
  5. Regular review
    • Monthly cost reviews
    • Tag-based cost allocation

🧪 Hands-On Lab: Deploy Scalable Web App

Objective: Deploy a Node.js application with Auto Scaling and Load Balancing
1

Create Launch Template

Configure EC2 instance with user data for automatic setup
2

Create Auto Scaling Group

Set min=2, max=6, desired=3 across 2 AZs
3

Create Application Load Balancer

Configure health checks and target group
4

Configure Scaling Policies

Add target tracking (CPU 50%) and step scaling
5

Test Scaling

Generate load with ab or hey and watch scaling in action

Next Module

Storage & Databases

Master S3, EBS, RDS, DynamoDB, and ElastiCache