Lab 3: Multi-AZ VPC Baseline
Lab นี้สร้าง VPC baseline แบบ 2 Availability Zones พร้อม Public/Private Subnets, Internet Gateway, NAT path, Security Group, VPC Flow Logs และ S3 Gateway Endpoint เพื่อเตรียมพื้นฐานสำหรับ Compute phase
Goal
สร้าง VPC 2 AZ ที่ route ชัดเจน
Public subnets ออกผ่าน IGW, private subnets ไม่ route ตรงเข้า IGW
Safety
NAT/public IPv4/Flow Logs มีค่าใช้จ่าย
ทำ lab ให้สั้น ตรวจผล แล้ว cleanup ทันทีถ้าไม่ใช้ต่อ
Output
VPC, 4 subnets, routes, SG, logs, S3 endpoint
สุดท้ายต้องอธิบาย traffic path จากแต่ละ subnet ได้
Run order
- Create VPC และ 4 subnets กระจาย 2 AZ
- Attach IGW แล้ว associate public route table ให้ public subnets
- สร้าง NAT path เฉพาะถ้าต้องทดสอบ outbound internet จาก private subnet
- สร้าง Security Groups, Flow Logs และ S3 Gateway Endpoint
- Verify route tables และ cleanup billable items ก่อน mark lab complete
Learning objectives
- ออกแบบ VPC CIDR และ subnet CIDR แบบไม่ overlap
- สร้าง public และ private subnet อย่างน้อย 2 AZ
- กำหนด route table สำหรับ IGW และ NAT Gateway
- สร้าง Security Group ตามหลัก Least Privilege
- เปิด VPC Flow Logs และสร้าง S3 Gateway Endpoint
- ตรวจสอบ routing และ cleanup เพื่อลดค่าใช้จ่าย
Prerequisites
- ผ่าน Phase 1 Budget baseline แล้ว
- ผ่าน Phase 2 IAM baseline และมีสิทธิ์สร้าง VPC, IAM role/log destination ตามที่ต้องใช้
- เลือก Region สำหรับเรียน เช่น
ap-southeast-1 - รู้วิธีลบ NAT Gateway, Elastic IP, Flow Logs และ VPC resource หลังจบ Lab
Cost warning: NAT Gateway, public IPv4, Flow Logs destination และ data processing อาจมีค่าใช้จ่าย
ถ้าต้องการลด cost ให้ทำ Lab สั้นๆ แล้ว cleanup ทันที หรือข้าม NAT Gateway ในรอบแรกและใช้ S3 Gateway Endpoint แทนสำหรับ S3 path
Target design
VPC: 10.0.0.0/16
AZ-A:
Public subnet: 10.0.1.0/24
Private subnet: 10.0.11.0/24
AZ-B:
Public subnet: 10.0.2.0/24
Private subnet: 10.0.12.0/24
Public route table:
10.0.0.0/16 -> local
0.0.0.0/0 -> Internet Gateway
Private route table:
10.0.0.0/16 -> local
0.0.0.0/0 -> NAT Gateway (optional / billable)
S3 prefix -> Gateway Endpoint
Step 1: Create VPC and subnets
- Create VPC CIDR
10.0.0.0/16with DNS hostnames and DNS resolution enabled - Create 2 public subnets in different AZs
- Create 2 private subnets in the same AZ pair
- Apply tags:
Environment=learning,Project=aws-infra-learning,ManagedBy=manual-lab
Step 2: Internet Gateway and public routing
- Create and attach Internet Gateway to the VPC
- Create public route table
- Add route
0.0.0.0/0to Internet Gateway - Associate public subnets with public route table
Step 3: NAT path for private subnets
- Allocate Elastic IP
- Create NAT Gateway in a public subnet
- Create private route table
- Add route
0.0.0.0/0to NAT Gateway - Associate private subnets with private route table
Cost-saving option: ถ้าไม่ต้องทดสอบ outbound internet จาก private subnet ให้ข้าม NAT Gateway และระบุไว้ใน notes
Step 4: Security Groups
ALB security group:
inbound TCP 443 from 0.0.0.0/0
outbound TCP 8080 to App security group
App security group:
inbound TCP 8080 from ALB security group
outbound TCP 443 to 0.0.0.0/0 or endpoint paths
Database security group:
inbound TCP 5432 from App security group only
Step 5: Flow Logs and S3 Gateway Endpoint
- Create VPC Flow Logs to CloudWatch Logs or S3 with short retention / lifecycle policy
- Create Gateway Endpoint for S3
- Attach endpoint to private route table
- Use endpoint policy if you want to restrict bucket access path
Expected results
Definition of done
- VPC contains 4 subnets across 2 Availability Zones
- Public subnets have route to Internet Gateway
- Private subnets have no direct route to Internet Gateway
- S3 Gateway Endpoint route appears in selected route table
- Flow Logs deliver records to selected destination
- NAT Gateway, Elastic IP และ test log data ถูก cleanup ถ้าไม่ใช้ต่อ
Verification steps
aws ec2 describe-vpcs --filters Name=tag:Project,Values=aws-infra-learning
aws ec2 describe-subnets --filters Name=vpc-id,Values=vpc-xxxxxxxx
aws ec2 describe-route-tables --filters Name=vpc-id,Values=vpc-xxxxxxxx
aws ec2 describe-vpc-endpoints --filters Name=vpc-id,Values=vpc-xxxxxxxx
Troubleshooting
| อาการ | แนวทางแก้ |
|---|---|
| Private subnet ออก Internet ไม่ได้ | ตรวจ NAT Gateway state, route table association, NACL และ outbound Security Group |
| Public subnet ไม่ reachable | ตรวจ IGW attached, route 0.0.0.0/0, public IPv4 assignment และ Security Group |
| S3 endpoint ไม่ทำงาน | ตรวจ endpoint route table association และ endpoint policy |
| Flow Logs ไม่มีข้อมูล | ตรวจ IAM permission, destination, log delivery delay และว่ามี traffic เกิดขึ้นจริง |
Cleanup procedures
- Delete NAT Gateway และรอจน deleted
- Release Elastic IP ที่ไม่ใช้แล้ว
- Delete VPC Endpoint
- Delete Flow Logs และ log group/bucket test data ถ้าไม่ต้องเก็บ
- Delete route tables, subnets, Internet Gateway และ VPC
- ตรวจ Cost Explorer วันถัดไปเพื่อยืนยันว่าไม่มี NAT/public IPv4 charge ต่อเนื่อง
Mini quiz
- Private subnet ต่างจาก public subnet ที่ route table ไม่ใช่ชื่อ subnet ใช่หรือไม่?
- ทำไม NAT Gateway ต้องอยู่ใน public subnet?
- S3 Gateway Endpoint ช่วยลดการพึ่ง NAT Gateway ได้อย่างไร?