🖥️ EC2 Instance Family
t3/t4g burstable (cheap) m5/m6i general purpose c5/c6i compute-optimized r5/r6i memory (DB) g4/g5 GPU Inf1/Trn1 AWS chips
💰 Pricing
- On-Demand — pay/hour
- Reserved 1-3yr — 40-72% off
- Savings Plan — flexible
- Spot — 90% off, interruptible
🚀 Launch
1. EC2 → Launch Instance 2. Ubuntu 22.04 LTS, t2.micro 3. Key pair download (.pem) 4. Security Group: - SSH 22 from My IP - HTTP/S 80,443 anywhere 5. 8GB gp3 6. Launch chmod 400 key.pem ssh -i key.pem ubuntu@ip
🛡️ Security Group
SSH 22 My IP only! HTTP 80 0.0.0.0/0 HTTPS 443 0.0.0.0/0 MySQL 3306 SG of app-server (not public) # Allow SG (not IP) for internal
📡 Elastic IP
Allocate → Associate to instance # Free if attached # $0.005/hr if unattached — delete!
💾 EBS Volume
gp3 general SSD (cheapest/fast) 🔥 gp2 older io2 high IOPS (DB) st1 throughput HDD # Live resize Modify volume → new size sudo growpart /dev/xvda 1 sudo resize2fs /dev/xvda1
📸 Snapshot & AMI
Snapshot — incremental EBS backup AMI — instance image (golden) Cross-region copy supported
📈 Auto Scaling
Launch Template → ASG min:2, max:10, desired:3 Target: CPU 70% + ALB for traffic distribute
🛠️ User Data (Bootstrap)
#!/bin/bash apt update -y apt install nginx -y systemctl enable --now nginx
💡 Cost Tips
- Stop dev night (save 65%)
- Spot for non-critical
- Right-size instance
- gp3 > gp2 (cheap+fast)
- Delete unused EBS/EIP/snapshot
- Reserved for steady prod
🎓 মূল কথা ⭐
SG = firewall। SSH 0.0.0.0 বন্ধ। EIP attached free। ASG+ALB = production scale। Stop dev night = 65% save।