AWS core services · Lesson 2 of 8 · 5 min read
Compute: EC2, Auto Scaling and load balancing
EC2 essentials
- Instance families: general (m, t burstable), compute (c), memory (r, x), storage (i, d), accelerated (g, p, inf). Graviton (
*g, ARM) gives better price/performance if your images support arm64. - Purchasing: On-Demand; Savings Plans (Compute SP flexible across EC2/Fargate/Lambda) and Reserved Instances for steady load; Spot (up to ~90% off, 2-minute interruption notice) for stateless/batch/CI and Karpenter node pools with diversification.
- AMIs — bake golden images (EC2 Image Builder/Packer); user data for bootstrap; IMDSv2 (session tokens) required to mitigate SSRF credential theft; hop limit 1 blocks containers from the node's credentials unless needed.
- Storage: EBS (network block, AZ-scoped) vs instance store (ephemeral, lost on stop).
- Placement groups: cluster (low latency), spread (separate hardware), partition (large distributed systems).
- Access: SSM Session Manager instead of SSH/bastions — no open port 22, IAM-controlled, logged.
Enlarge diagram
Swipe sideways to see all of it, or tap to open it full screen.
Enlarge diagram
Swipe sideways to see all of it, or tap to open it full screen.
Auto Scaling groups
- Launch template (AMI, type, SG, user data, IMDSv2) + ASG (min/desired/max, subnets across AZs).
- Scaling policies: target tracking (e.g. CPU 50%, ALB requests per target), step scaling, scheduled, predictive.
- Health checks: EC2 status or ELB health checks (replace instances the LB considers unhealthy); grace period for boot time.
- Instance refresh for rolling AMI updates with min healthy percentage; lifecycle hooks to drain or run scripts on launch/terminate; warm pools for slow-booting apps.
- Mixed instances policy — On-Demand base + Spot with multiple instance types and capacity-optimised allocation.
Enlarge diagram
Swipe sideways to see all of it, or tap to open it full screen.
Elastic Load Balancing
| ALB | NLB | GWLB | |
|---|---|---|---|
| Layer | 7 (HTTP/HTTPS/gRPC, WebSockets) | 4 (TCP/UDP/TLS) | 3 (appliances) |
| Routing | Host/path/header/query rules, weighted target groups | Port-based | To firewall appliances via GENEVE |
| IPs | Dynamic (use DNS name/alias) | Static IP per AZ, Elastic IPs possible | — |
| Client IP | X-Forwarded-For |
Preserved (or proxy protocol) | — |
| Extras | WAF, Cognito/OIDC auth, redirects, fixed responses | Ultra-low latency, millions of rps, PrivateLink service | Inspection |
- Target types: instance, IP (pods with the AWS Load Balancer Controller —
target-type: ip), Lambda. - Health checks per target group; deregistration delay (connection draining, default 300 s — tune down for fast deploys, align with pod
preStopsleeps). - Cross-zone load balancing: always on for ALB; off by default on NLB (charges apply when on).
- TLS termination with ACM certificates; SNI for multiple certs; security policies for TLS versions.
- 502 = target returned an invalid response/closed connection (app crash, keep-alive timeout shorter than ALB idle timeout); 503 = no healthy targets; 504 = target timed out.
Enlarge diagram
Swipe sideways to see all of it, or tap to open it full screen.