EC2
Elastic Compute Cloud
🎯 Sebab Apa Wujud
Dulu nak run aplikasi kena beli server fizikal, tunggu berminggu, setup data center sendiri — mahal & lambat. EC2 wujud bagi kau 'sewa' virtual server dalam minit, scale up/down ikut keperluan, bayar ikut guna, dengan full control atas OS. Pain yang ia buang: tak payah beli/jaga hardware fizikal untuk dapat compute dengan kawalan penuh.
Apa Dia
Menyediakan kapasiti compute yang boleh diubah saiz dalam cloud
Contoh Guna
Host web server, run database, legacy app migration
Placement Groups — macam mana EC2 disusun atas hardware fizikal
| Aspect | Cluster | Partition | Spread |
|---|---|---|---|
| Susunan | Pack RAPAT dalam 1 AZ, segment network high-bandwidth sama | Bahagi kepada partition; tiap partition guna rack (kuasa + network) berasingan | Tiap instance atas hardware BERLAINAN (rack berbeza) |
| Tujuan | 🟢 Latency rendah + throughput tinggi (sampai 10 Gbps single-flow) | 🟢 Hadkan kesan kegagalan hardware ke satu partition sahaja | 🟢 Kurangkan correlated failure — instance kritikal tak fail serentak |
| Best untuk | HPC, tightly-coupled (banyak traffic node-to-node) | Big data teragih: HDFS, HBase, Cassandra, Kafka | Segelintir instance kritikal (cth domain controller, node quorum) |
| Span AZ? | 🔴 1 AZ sahaja | 🟢 Multi-AZ (maks 7 partition / AZ) | 🟢 Multi-AZ (maks 7 instance / AZ / group) |
| Tahan failure | Paling lemah — 1 rack/AZ jatuh, semua kena | Sederhana — failure terhad ke 1 partition | 🟢 Paling tahan — hardware berasingan sepenuhnya |
Ingat: Cara ingat 3C-P-S: Cluster = "Close" (rapat, low-latency HPC). Partition = "Pisah rack" (big data teragih — Hadoop/Cassandra/Kafka). Spread = "Separate hardware" (instance kritikal, maks 7/AZ). Placement group PERCUMA. Satu instance = satu placement group sahaja; tak boleh merge group.
⚡ Quick Sifir — hafal ni
- ▪Cluster PG = low-latency/HPC (1 AZ); Partition = big data teragih (Hadoop/Kafka); Spread = critical instances (maks 7/AZ)
- ▪On-Demand = no commit; Reserved/Savings Plan = commit 1-3yr (jimat ~72%); Spot = ~90% murah (boleh reclaim)
- ▪Spot interruption notice = 2 minit
- ▪Linux billing per-second (min 60s); Windows per-hour
- ▪Dedicated Host = bayar per-host (BYOL lesen); Dedicated Instance = +region fee tapi tak dapat host visibility
💡 Exam Scenario
"Full control atas OS / custom kernel / lift-and-shift legacy app" → EC2. "Lowest latency / HPC node-to-node" → Cluster placement group. "Fault-tolerant + cheapest + interruptible" → Spot. "Steady predictable 1-3yr" → Reserved/Savings Plans. "Per-second billing (Linux)" → EC2. "EC2 + RDS jalan office-hours/weekday je, jimat kos least ops" → AWS Instance Scheduler (start/stop ikut jadual), BUKAN Savings Plan/RI (commit) atau custom CloudWatch+Lambda (lebih ops). Kerja pendek event-driven & nak scale-to-zero → Lambda, BUKAN EC2.
🪤 Perangkap Soalan
Q: HPC workload perlu node-to-node latency paling rendah + throughput paling tinggi. Placement group mana?
⚠ Umpan: Spread placement group — 'spread' bunyi macam bagus untuk performance, tapi spread = sebar untuk availability, bukan low latency.
✓ Betul: Cluster placement group — keyword 'lowest latency / highest throughput / HPC / tightly-coupled' = Cluster (1 AZ).
Q: Batch job boleh interrupt, nak jimat kos maksimum, tak kisah kalau instance kena ambil balik. Pilih apa?
⚠ Umpan: Reserved Instance — jimat tapi kena commit 1-3 tahun; untuk workload sementara/interruptible ia bukan paling murah.
✓ Betul: Spot Instances — keyword 'fault-tolerant / interruptible / cheapest / flexible timing' = Spot (sampai 90% off, 2-min notice).
Q: EC2 + RDS PostgreSQL jalan waktu pejabat weekday SAHAJA. Nak optimize kos dengan operational overhead MINIMUM. Pilih apa?
⚠ Umpan: Compute Savings Plan / Reserved Instance untuk EC2 & RDS — nampak jimat, tapi commit 24/7 selama 1-3 tahun = kau bayar masa malam & weekend yang kau langsung tak guna. Bukan optimal untuk part-time.
✓ Betul: Deploy AWS Instance Scheduler (CloudFormation template) — auto start/stop EC2 + RDS ikut jadual office-hours. Custom CloudWatch alarm + Lambda boleh juga TAPI lebih ops (build & maintain sendiri). Instance Scheduler = ready-made, least overhead.
🧠 Cara Mudah Ingat
- →Soalan sebut "lowest latency / highest throughput / HPC" → Cluster. Sebut "large distributed/replicated (Hadoop, Cassandra, Kafka)" → Partition. Sebut "critical instances mesti elak simultaneous failure" → Spread
- →SCHEDULE / part-time — "EC2 + RDS jalan waktu kerja je (weekday office hours), nak jimat kos, least ops" → deploy AWS Instance Scheduler on AWS (AWS Solution, CloudFormation template) untuk auto start/stop EC2 & RDS ikut jadual. JANGAN pilih Savings Plan/Reserved (commit penuh 1-3thn = bazir untuk part-time) atau custom CloudWatch alarm + Lambda (boleh, tapi kena build & maintain sendiri = lebih ops overhead).
- →Spread = maks 7 running instances per AZ per group; Partition = maks 7 partition per AZ — angka 7 ni selalu jadi distractor exam
- →EC2 purchasing: On-Demand (bayar ikut guna, no commit) · Reserved/Savings Plans (commit 1–3 thn, jimat sampai ~72%) · Spot (sampai 90% murah, boleh kena reclaim) · Dedicated Host (hardware fizikal khas, untuk lesen BYOL)
- →PRICING: (us-east-1, t3.medium approx) On-Demand ~$0.0416/hr. Reserved (3yr All Upfront) ~72% off. Savings Plans ~66% off. Spot up to 90% off. Dedicated Instance: +$2/hr region fee. Dedicated Host: billed per-host (~$3.20/hr for t3 host). Billing: Linux/Ubuntu per-second (min 60s), Windows per-hour. (Lihat card On-Demand / Reserved / Spot / Savings Plans dalam Domain 4 untuk perincian setiap model.)
- →Exam: "Linux per-second billing, minimum 60 seconds" → EC2. "Windows billed per-hour" → EC2 Windows. "Dedicated Host billed per physical host" → not per-instance.
Guna Bila
Run any workload, full control