Hands-on LabCreates billable resources

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
  1. Create VPC และ 4 subnets กระจาย 2 AZ
  2. Attach IGW แล้ว associate public route table ให้ public subnets
  3. สร้าง NAT path เฉพาะถ้าต้องทดสอบ outbound internet จาก private subnet
  4. สร้าง Security Groups, Flow Logs และ S3 Gateway Endpoint
  5. 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

  1. Create VPC CIDR 10.0.0.0/16 with DNS hostnames and DNS resolution enabled
  2. Create 2 public subnets in different AZs
  3. Create 2 private subnets in the same AZ pair
  4. Apply tags: Environment=learning, Project=aws-infra-learning, ManagedBy=manual-lab

Step 2: Internet Gateway and public routing

  1. Create and attach Internet Gateway to the VPC
  2. Create public route table
  3. Add route 0.0.0.0/0 to Internet Gateway
  4. Associate public subnets with public route table

Step 3: NAT path for private subnets

  1. Allocate Elastic IP
  2. Create NAT Gateway in a public subnet
  3. Create private route table
  4. Add route 0.0.0.0/0 to NAT Gateway
  5. 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

  1. Create VPC Flow Logs to CloudWatch Logs or S3 with short retention / lifecycle policy
  2. Create Gateway Endpoint for S3
  3. Attach endpoint to private route table
  4. Use endpoint policy if you want to restrict bucket access path

Expected results

Definition of done
  1. VPC contains 4 subnets across 2 Availability Zones
  2. Public subnets have route to Internet Gateway
  3. Private subnets have no direct route to Internet Gateway
  4. S3 Gateway Endpoint route appears in selected route table
  5. Flow Logs deliver records to selected destination
  6. 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

  1. Delete NAT Gateway และรอจน deleted
  2. Release Elastic IP ที่ไม่ใช้แล้ว
  3. Delete VPC Endpoint
  4. Delete Flow Logs และ log group/bucket test data ถ้าไม่ต้องเก็บ
  5. Delete route tables, subnets, Internet Gateway และ VPC
  6. ตรวจ Cost Explorer วันถัดไปเพื่อยืนยันว่าไม่มี NAT/public IPv4 charge ต่อเนื่อง

Mini quiz

  1. Private subnet ต่างจาก public subnet ที่ route table ไม่ใช่ชื่อ subnet ใช่หรือไม่?
  2. ทำไม NAT Gateway ต้องอยู่ใน public subnet?
  3. S3 Gateway Endpoint ช่วยลดการพึ่ง NAT Gateway ได้อย่างไร?