PEBD6027 · RPS minggu 5 · 2x50 menit
AWS EC2 Hands-on
Compute Services — Launch Instance, AMI, Security Group, Key Pair
Peta Pembelajaran Hari Ini
Sub-CPMK 5: memprovision instance AWS EC2 dari nol. Empat indikator capaian.
- Konsep EC2: instance, AMI, instance type
- Security group & key pair
- Launch instance via Console step-by-step
- SSH ke instance via terminal
- Install & jalankan web server nginx
- Elastic IP & billing alert anti-bocor
Posisi alur 14P: setelah virtualisasi & container (P4), hari ini compute service cloud. P6 storage S3/EBS.
Mengapa EC2 adalah Service #1 AWS
EC2 (Elastic Compute Cloud) diluncurkan 2006 — service pertama & paling fundamental AWS. Tanpa EC2, tidak ada cloud modern.
Diluncurkan
2006
service pertama AWS (S3 sedikit lebih awal)
Instance Type
450+
kombinasi vCPU/RAM/network (estimasi)
Pertanyaan pemantik: berapa instance minimum untuk startup web app? Berapa maksimum untuk Tokopedia Harbolnas?
Bagian 1 · 1/4
Konsep EC2 Anatomi
Diskusi kelas: apa beda AMI dengan instance? Sama dengan image vs container Docker?
Anatomi EC2: Instance, AMI, Type
Empat konsep inti yang wajib Anda kuasai sebelum launch instance pertama.
- Virtual server running di AWS
- Dibuat dari AMI
- Punya IP private & opsional public
- Dikenai biaya per detik/jam
- Blueprint read-only OS + software
- Contoh: Amazon Linux 2, Ubuntu 22.04
- Bisa custom (snapshot instance)
- Bisa dari AWS Marketplace
- Kombinasi vCPU, RAM, network, storage
- t3.micro = 2 vCPU, 1 GB (free tier)
- m5.large = 2 vCPU, 8 GB (general)
- c5.2xlarge = 8 vCPU, 16 GB (compute)
- SSH key untuk akses instance Linux
- Private key disimpan lokal (jangan bocor)
- Public key di-upload ke AWS
- RSA 2048 atau ED25519
Instance type menentukan biaya & performa. t3.micro free tier 750 jam/bulan selama 12 bulan.
Security Group: Firewall Stateful
Security group adalah firewall virtual per instance — stateful, default deny all inbound.
- Stateful: return traffic otomatis diizinkan
- Default: deny all inbound, allow all outbound
- Per instance, per VPC
- Rule: allow only (tidak ada deny)
- SSH: TCP 22 dari IP Anda saja (jangan 0.0.0.0/0)
- HTTP: TCP 80 dari 0.0.0.0/0 (public)
- HTTPS: TCP 443 dari 0.0.0.0/0
- DB PostgreSQL: TCP 5432 dari SG app saja
Mistake #1 pemula: buka SSH ke 0.0.0.0/0 = bot brute-force dalam menit. Always restrict SSH ke IP Anda.
Hitung dari Nol: On-demand vs Reserved
t3.small us-east-1. On-demand $0,0208/jam. Reserved 1 tahun all upfront ~40% hemat. Penggunaan 24/7.
| Langkah | Skenario | Perhitungan | Nilai |
|---|
| 1 | On-demand 730 jam/bulan | 730 × $0,0208 | $15,18/bulan |
| 2 | Reserved all upfront effective | 730 × $0,0125 | $9,13/bulan |
| 3 | Selisih per bulan | $15,18 − $9,13 | $6,05/bulan |
| 4 | Akumulasi setahun | $6,05 × 12 | $72,60/tahun hemat |
| 5 | Upfront reserved t3.small | bayar sekali di awal | ~$110 (commitment) |
| 6 | Break-even steady usage | >70% waktu running | Reserved menang |
Harga AWS public pricing (dihedge — verify via Pricing Calculator). Untuk dev/test <30% gunakan on-demand.
Bagian 2 · 2/4
Launch Instance Step-by-step
Diskusi: region mana yang dipilih untuk target pengguna Indonesia?
Launch Instance via AWS Console
Lima langkah launch instance dari Console — ikuti live bersama saya.
1. Console > EC2 > Launch instance
2. Pilih AMI: Amazon Linux 2 (free tier eligible)
3. Instance type: t3.micro (free tier)
4. Key pair: create new (RSA, download .pem)
5. Network: default VPC, auto-assign public IP
6. Security group: SSH (22) dari My IP, HTTP (80) dari anywhere
7. Storage: 8 GB gp3 (free tier)
8. Launch!
Catat instance ID & public IP. Kita akan SSH di Slide berikutnya.
AMI Marketplace & Custom AMI
Selain AMI resmi AWS, ada Marketplace untuk software pre-installed & custom AMI untuk standar internal.
| Sumber AMI | Use Case | Contoh |
|---|
| AWS Quick Start AMI | OS standar free tier | Amazon Linux 2, Ubuntu 22.04, Debian 12 |
| AWS Marketplace | Software pre-installed berbayar | WordPress Bitnami, Nginx Plus, Cisco firewall |
| Community AMI | Kontribusi komunitas | CentOS, Fedora, custom distro |
| Custom AMI (snapshot) | Standar internal perusahaan | Hardened base, app pre-configured |
Bank & enterprise biasanya pakai custom AMI untuk compliance (hardened, audited). Startup pakai AWS Quick Start untuk cepat.
Bagian 3 · 3/4
SSH & Web Server
Diskusi: mengapa 0.0.0.0/0 untuk SSH berbahaya? Berapa lama bot brute-force menemukan instance?
SSH ke Instance Linux
Setelah instance running & status check OK, SSH via terminal. Jangan lupa chmod 400 untuk key permission.
# Set permission key (Windows: skip, Mac/Linux:)
chmod 400 mykey.pem
# SSH ke instance (ganti IP dengan public IP Anda)
ssh -i mykey.pem ec2-user@13.250.123.45
# Accept fingerprint, lalu Anda di dalam instance!
User default: ec2-user (Amazon Linux), ubuntu (Ubuntu), admin (Debian), centos (CentOS).
Install Web Server Nginx
Setelah SSH, install nginx untuk hosting static site. Tes via browser ke public IP instance.
# Update package list
sudo yum update -y # Amazon Linux
sudo apt update -y # Ubuntu
# Install nginx
sudo yum install nginx -y # Amazon Linux
sudo apt install nginx -y # Ubuntu
# Start & enable
sudo systemctl start nginx
sudo systemctl enable nginx
# Test: buka http://PUBLIC-IP — halaman default nginx muncul
Bila timeout, cek security group: HTTP 80 dari 0.0.0.0/0?
Studi Kasus: Hosting Static Site di EC2
Skenario realistis: UMKM portofolio fotografer butuh landing page. Static site di EC2 cukup, murah, cepat.
- Beli domain di Namecheap/Rumahweb (~Rp 150rb/thn)
- Point A record ke public IP EC2
- Upload file HTML/CSS/JS ke /usr/share/nginx/html
- Install Certbot untuk HTTPS free (Let's Encrypt)
- EC2 t3.micro free tier: Rp 0 (12 bln)
- Domain .com: ~Rp 150rb/thn
- Route 53 DNS: ~Rp 8rb/bulan
- HTTPS Let's Encrypt: Rp 0
- Total: ~Rp 250rb/thn pertama
Alternatif lebih murah: S3 static hosting + CloudFront (~Rp 30rb/bulan). EC2 overkill bila hanya static.
Bagian 4 · 4/4
Instance Type & Cost Optimization
Diskusi: kapan harus pilih spot instance? Apa risikonya untuk production?
Elastic IP & Billing Alert Anti-Bocor
Elastic IP = IP static untuk instance. Billing alert = early warning tagihan. Wajib setup keduanya.
- IP static yang tidak berubah saat stop/start
- Free bila ter-attach ke instance running
- Charge kecil bila tidak attached (~Rp 5rb/bulan)
- Cocok untuk server dengan DNS A record
- Alert email bila tagihan melewati threshold
- Setup $1 threshold untuk free tier (early warning)
- Per service alert: EC2, S3, data transfer
- Wajib sebelum hari pertama production
Free tier tidak ada hard stop — bila over limit, Anda tetap dikenai biaya. Billing alert #1 pertahanan.
Spot Instance & Savings Plan
Tiga model pembelian EC2: on-demand (fleksibel), reserved (steady hemat ~40%), spot (batch hemat ~90%).
| Model | Hemat | Karakteristik | Cocok untuk |
|---|
| On-demand | 0% | Bayar per jam, no commitment | Dev/test, spiky unpredictable |
| Reserved (1-3 thn) | ~30-72% | Commitment upfront/all/no | Production steady (web tier, DB) |
| Spot | ~90% | Bisa diterminasi 2 menit notice | Batch, CI/CD, big data, rendering |
| Savings Plan | ~30-60% | Commit $/jam spend (lebih fleksibel) | Mix EC2+Fargate+Lambda |
Strategi FinOps P13: 70% reserved + 20% spot + 10% on-demand untuk fleet production. Hemat ~50%.
Ringkasan Kunci Pertemuan 5
Hari ini Anda meluncurkan instance EC2 pertama — skill fundamental cloud engineer.
Instance & AMI
Blueprint read-only + running VM. Instance type menentukan vCPU/RAM.
Security Group
Stateful firewall, default deny inbound. SSH 22 restrict IP Anda.
Cost Model
On-demand/reserved/spot. Mix untuk optimasi FinOps.
Tiga lensa P5: instance & AMI · security group stateful · cost model 3-tier.
Persiapan P6: Cloud Storage S3/EBS/EFS. Baca Wittig bab 6-7. Kuis 5 menit soal EC2 anatomi & cost model.
Instance Lifecycle & Status Check
Instance punya lifecycle: pending → running → stopping → stopped → terminated. Pahami untuk debugging.
| Status | Arti | Charge? |
|---|
| pending | Sedang boot, belum siap | Ya, per detik |
| running | Aktif & siap melayani traffic | Ya |
| stopping | Sedang shutdown graceful | Ya |
| stopped | Dimatikan, boot disk tetap | Tidak untuk compute, ya untuk EBS |
| terminated | Dihapus permanen + boot disk | Tidak (seluruh resource dilepas) |
Status check 2/2: instance running + system reachable. Bila 0/2 = network issue, 1/2 = OS issue.
User Data: Bootstrap Script Otomatis
User Data adalah script yang dijalankan otomatis saat instance pertama boot — powerful untuk automation.
#!/bin/bash
yum update -y
yum install nginx -y
systemctl start nginx
systemctl enable nginx
echo "<h1>Hello Cloud Bisdig</h1>" > /usr/share/nginx/html/index.html
Dengan User Data, instance bisa auto-setup tanpa SSH manual. Dasar Infrastructure as Code P10 Terraform.