EC2 and Auto Scaling
Amazon EC2 (Elastic Compute Cloud) provides scalable virtual servers in the AWS cloud. Combined with Auto Scaling, EC2 ensures you have the right amount of compute power at the right time.
EC2 Instance Types
ββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Instance Type β Best For β
ββββββββββββββββββββΌβββββββββββββββββββββββββββββββ€
β t3, t3a β Burstable: dev, test, small β
β β web apps β
β m5, m6i β General: balanced compute β
β β and memory β
β c5, c6i β Compute: CPU-intensive tasks β
β β like batch processing β
β r5, r6i β Memory: in-memory databases, β
β β real-time analytics β
β g4, g5 β GPU: machine learning, video β
β β rendering, gaming β
β i3 β Storage: high I/O workloads β
β β like NoSQL databases β
ββββββββββββββββββββ΄βββββββββββββββββββββββββββββββ
EC2 Lifecycle
ββββββββββ start ββββββββββ running ββββββββββ
βStopped ββββββββββΆβPending ββββββββββββΆβ Runningβ
ββββββββββ ββββββββββ ββββββ¬ββββ
stop/rebootβterminate
βββββββΌβββββ
βStopped/ β
βTerminatedβ
ββββββββββββ
Key states: Stopped (not running, you still pay for storage), Running (actively running, you pay per hour/second), Terminated (deleted, storage is freed).
Auto Scaling Groups (ASG)
ASGs automatically adjust the number of EC2 instances based on demand. You define minimum, maximum, and desired capacity. CloudWatch alarms trigger scaling actions.
Traffic Spikes: Auto Scaling Response:
ββββββββββββ ββββββββββββ
β High β CloudWatch β Scale UP β
β CPU (80%)β Alarm Triggers β +2 EC2 β
ββββββ¬ββββββ ββββββ¬ββββββ
β β
βΌ βΌ
ββββββββββββ ββββββββββββ
β Low β CloudWatch βScale DOWN β
β CPU (20%)β Alarm Triggers β -1 EC2 β
ββββββββββββ ββββββββββββ
Cost Tips
Use Spot Instances for fault-tolerant workloads β save up to 90%. Use Reserved Instances or Savings Plans for predictable workloads β save up to 72%. Use On-Demand for unpredictable, short-term needs. Always set up billing alerts to avoid surprises.