Module Overview
Estimated Time: 4-5 hours | Difficulty: Intermediate | Prerequisites: Core Concepts
- 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 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
Q1: When would you choose Lambda over EC2?
Q1: When would you choose Lambda over EC2?
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
- Long-running processes
- Need specific OS/hardware (GPUs)
- Consistent, predictable traffic
- Cost optimization with Reserved Instances
- Need persistent connections (WebSockets)
Q2: How do you reduce Lambda cold starts?
Q2: How do you reduce Lambda cold starts?
Strategies:
- Provisioned Concurrency - Pre-warm containers
- Smaller packages - Reduce initialization time
- Initialize outside handler - SDK clients, DB connections
- Use lighter runtimes - Go, Python, Node.js
- SnapStart for Java - Checkpoint/restore
- Keep functions warm - Scheduled pings (not ideal)
Q3: ECS vs EKS - when to use each?
Q3: ECS vs EKS - when to use each?
Choose ECS when:
- AWS-native, simpler setup
- Smaller team without K8s expertise
- Tighter AWS integration needed
- Lower operational overhead
- Multi-cloud strategy
- Team has Kubernetes expertise
- Need K8s ecosystem (Helm, operators)
- Complex microservices architectures
- Portability is important
Q4: Design an auto-scaling strategy for an e-commerce site
Q4: Design an auto-scaling strategy for an e-commerce site
Multi-layered approach:
- Predictive Scaling: Scale up before known peaks (Black Friday)
- Target Tracking: Maintain 50% CPU average
- Step Scaling: Add extra capacity for sudden spikes
- Minimum: 4 instances (2 per AZ)
- Desired: 6 instances (normal load)
- Maximum: 50 instances (peak capacity)
- 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
- Scale-out: 60 seconds
- Scale-in: 300 seconds (avoid thrashing)
Q5: How do you optimize EC2 costs?
Q5: How do you optimize EC2 costs?
Framework (in order of impact):
-
Right-size (15-30% savings)
- Use Compute Optimizer
- Monitor actual utilization
-
Purchase options (30-72% savings)
- Reserved for baseline (60-70% of capacity)
- Spot for stateless/batch
- Savings Plans for flexibility
-
Instance selection (20-40% savings)
- Graviton (ARM) for compatible workloads
- Latest generation (m7 vs m5)
-
Shutdown automation
- Stop dev/test outside hours
- Auto-scaling to zero when possible
-
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 Balancing1
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 actionNext Module
Storage & Databases
Master S3, EBS, RDS, DynamoDB, and ElastiCache