Sitemap

AWS Level 2

7 min readJan 28, 2026

--

Materi: Establishing Secure Communication Between Public and Private VPCs via VPC Peering

jadi tugasnya yaitu agar EC2 public bisa melakukan ping ke EC2 private.

nantinya menghubungkan dua VPC yang terpisah menggunakan VPC Peering . Jadi nanti kita akan membuat VPC Peering lalu kita update route table di kedua VPC dan update Security Group

VPC Peering itu adalah kabel langsung yang menghubungkan dua VPC.

Analogi projectnya:

🏘️ Kompleks A (Default VPC)
|
| (VPC Peering = jalan tol)
|
🏘️ Kompleks B (Private VPC)

Alur kemungkinan seperti ini nanti nya:

  • Create VPC Peering
    → Accept peering
    → Update route table (default VPC)
    → Update route table (private VPC)
    → Update security group
    → SSH ke public EC2
    → Ping private EC2

oKEyy kita mulai projectnyaa

  1. pertama yang dilakkukan kita ke service vpc lalu kita cari yang namanya Peering Connections. kita buat requestnya ke Default VPC dan juga Accepter nya yaitu VPC Private.
Press enter or click to view image in full size
Create VPC Peering

2. lalu melakukan Accept Request

Press enter or click to view image in full size

3. Lalu melakukan update Route Table pada VPC Default

Destination: 10.1.0.0/16
Target: devops-vpc-peering

Press enter or click to view image in full size

4. Update Route Table Private VPC

Destination: <CIDR Default VPC>
Target: devops-vpc-peering

Press enter or click to view image in full size

5. Update Security Groups

Private EC2 Security Group

Inbound rules → tambah:

Type: ICMP (Echo Request)
Source: Default VPC CIDR (172.31.0.0/16)

Press enter or click to view image in full size

agar ping dari public EC2 diperbolehkan.

6. Login ke Public EC2 (Console / SSH)

Test Connection SSH ke Public EC2 ssh ec2-user@<PUBLIC_EC2_IP>

Melakukan Ping Private EC2

Press enter or click to view image in full size

BERHASIL

Setting Up a Private VPC with an Isolated EC2 Instance

membuat VPC private (tidak terhubung ke internet).

Di dalamnya dibuat subnet private.

EC2 dibuat di subnet private.

Security Group hanya mengizinkan akses dari dalam VPC.

tujuan projectnya:
EC2 tidak punya public IP dan tidak bisa diakses dari internet.

Alur Projectnya

Create Private VPC
→ Create private subnet
→ Create EC2 di subnet
→ Security Group allow only VPC CIDR
→ EC2 hanya bisa diakses internal
  1. Create VPC

IPv4 CIDR: 10.2.0.0/16

Press enter or click to view image in full size

2. Create Private Subnet

  • IPv4 CIDR:
10.2.1.0/24
Press enter or click to view image in full size

3. Create EC2 di Private VPC

Network Settings:

  • VPC:
devops-priv-vpc
  • Subnet:
devops-priv-subnet
Press enter or click to view image in full size

Security Group

Inbound rules:

Allow hanya dari CIDR VPC sendiri.

Type: SSH
Port: 22
Source: 10.2.0.0/16

Press enter or click to view image in full size

Public IP: TIDAK ADA ✅

Press enter or click to view image in full size

Troubleshooting Internet Accessibility for an EC2-Hosted Application

TROUBLESHOOTING EC2 PUBLIC WEB (NGINX TIDAK BISA DIAKSES)

Security Group (port 80 open)

  • Agar EC2 bisa diakses dari internet, VPC + Subnet + Route Table + IGW harus benar.
  • Masalah paling sering:
  • ❌ Internet Gateway tidak ada / tidak terhubung
  • ❌ Route table tidak punya 0.0.0.0/0 → IGW
  • ❌ Subnet bukan public
  • ❌ EC2 tidak punya public IP

Agar EC2 bisa diakses dari internet, SEMUA ini HARUS BENAR:

1. VPC punya Internet Gateway
2. Internet Gateway ter-attach ke VPC
3. Route table subnet punya:
0.0.0.0/0 → IGW
4. Subnet = public
5. EC2 dapat public IP
6. Security Group allow port 80
7. Nginx running

  1. Verify Internet Gateway

Pastikan:

  • Ada IGW
  • Status: Attached
  • Attached ke:
devops-vpc
Press enter or click to view image in full size

2. Verify Route Table

Harus ada route ini:

Destination: 0.0.0.0/0
Target: igw-xxxxxxxx
Press enter or click to view image in full size

3. Pastikan Subnet BENAR-BENAR Public

Subnet disebut public kalau:

  • Route ke IGW ada
  • Auto-assign public IP aktif

Cek:

  1. VPC → Subnets
  2. Pilih subnet
  3. Edit subnet settings

Enable auto-assign public IPv4 address ✔️

Press enter or click to view image in full size

4. Cek EC2 Punya Public IP

Press enter or click to view image in full size

5. Test dari Browser

http://PUBLIC-IP

Press enter or click to view image in full size

TROUBLESHOOTING EC2 TIDAK BISA INSTALL PACKAGE

  • EC2 tidak punya jalur keluar ke internet.

Penyebab paling umum:

EC2 ada di private subnet TANPA NAT

Atau route table salah

Get Gloryemyu’s stories in your inbox

Join Medium for free to get updates from this writer.

Solusi:

  • Tambahkan NAT Gateway atau
  • Pindahkan EC2 ke public subnet + IGW

Alur Debug

Kita debug berurutan:

EC2
→ Subnet
→ Route Table
→ Internet Gateway / NAT
  1. Cek Subnet EC2

EC2 → Instances

  1. Klik datacenter-ec2
  2. Lihat:
  • VPC
  • Subnet

Apakah ini public subnet atau private subnet?

Press enter or click to view image in full size

2. Cek Route Table

  • Pastikan VPC punya Internet Gateway
  • Route table subnet:
  • 0.0.0.0/0 → IGW
  • Subnet:
  • Enable auto-assign public IP
Press enter or click to view image in full size

3. Security Group EGRESS (OUTBOUND) DIBLOKIR ❗❗❗

Default Security Group AWS:

Outbound: ALL TRAFFIC → 0.0.0.0/0

Masuk ke Security Group nautilus-ec2, lalu lihat:

Outbound rules

Harus ada:

All traffic
Destination: 0.0.0.0/0

Creating a Private ECR Repository

ECR + BUILD DOCKER IMAGE + PUSH KE AWS

  • Kita akan membuat private ECR repository di AWS.
  • Kita akan build Docker image dari Dockerfile yang sudah ada.
  • Image tersebut akan di-tag latest dan di-push ke ECR.
  • Ini adalah alur standar industri untuk deploy aplikasi container.

Apa itu ECR?

ECR (Elastic Container Registry) adalah:

  • tempat menyimpan Docker image

Alur Kerja

Create ECR repo
→ Login Docker ke ECR
→ Build Docker image
→ Tag image ke ECR
→ Push image ke ECR

1. Create Repository

  1. Services → ECR
Press enter or click to view image in full size

catat <ACCOUNT_ID>.dkr.ecr.us-east-1.amazonaws.com/devops-ecr

Press enter or click to view image in full size

atau bisa dengan docker cli Ambil Account ID

aws sts get-caller-identity

2. Login ke ECR

aws ecr get-login-password --region us-east-1 \
| docker login --username AWS --password-stdin <ACCOUNT_ID>.dkr.ecr.us-east-1.amazonaws.com
Press enter or click to view image in full size

3. Build Docker Image

A. Masuk ke directory Dockerfile

cd /root/pyapp

4. Build Image

docker build -t devops-ecr:latest .
Press enter or click to view image in full size

5. Tag Image ke ECR

Docker tidak tahu image mau dikirim ke ECR.

docker tag devops-ecr:latest <ACCOUNT_ID>.dkr.ecr.us-east-1.amazonaws.com/devops-ecr:latest

6. Push Image ke ECR

docker push 547914434401.dkr.ecr.us-east-1.amazonaws.com/devops-ecr:latest
Press enter or click to view image in full size

7. Verifikasi

Press enter or click to view image in full size

Image berhasil di-push ke ECR

Configure NAT Gateway for Internet Access in a Private VPC

  • EC2 di private subnet TIDAK BISA internet langsung.
  • Untuk outbound internet (apt update, upload ke S3), HARUS pakai NAT Gateway.
  • NAT Gateway HARUS berada di public subnet.
  • Setelah NAT aktif:
  • EC2 private bisa keluar internet
  • Tapi tidak bisa diakses dari internet

Create Public Subnet
→ Create Internet Gateway
→ Attach IGW to VPC
→ Create Public Route Table
→ Create Elastic IP
→ Create NAT Gateway (di public subnet)
→ Update Private Route Table (0.0.0.0/0 → NAT)
→ Tunggu cron upload ke S3

  1. Create Public Subnet
Press enter or click to view image in full size

2. Create Internet Gateway

Press enter or click to view image in full size

3. Create Public Route Table

VPC → Route Tables

Create route table

Press enter or click to view image in full size

Edit routes → Add:

Destination: 0.0.0.0/0
Target: devops-igw

Associate subnet:

devops-pub-subnet
Press enter or click to view image in full size

4. Allocate Elastic IP

EC2 → Elastic IPs

Allocate Elastic IP

Simpan (akan dipakai NAT)

Press enter or click to view image in full size

5. Buat NAT GATEWAY

VPC → NAT Gateways

Press enter or click to view image in full size

hasil dari elastic ip tadi dipakai di NAT GATEWAY

6. Update Private Route Table (INI KUNCI ⚠️)

  1. VPC → Route Tables
  2. Pilih route table milik devops-priv-subnet
  3. Edit routes → Add:
Destination: 0.0.0.0/0
Target: devops-natgw
Press enter or click to view image in full size
Press enter or click to view image in full size
Press enter or click to view image in full size

test file (hasil upload cron)

file muncul → TASK SUKSES

--

--