Lab 4 — Configure High Availability in Your Amazon VPC
🧠 ภาพจำก่อนอ่าน: 🧪 Lab → 🧠 Concept → 🗺️ Flow → 🔎 Check → ✅ Explain → 🧹 Cleanup
🎨 Visual Guide ของวิชานี้ — ดูภาพช่วยจำ แล้วอ่านรายละเอียด/คำสั่งในบทนี้
🗺️ Lab architecture
หัวข้อที่มีชื่อว่า “🗺️ Lab architecture”flowchart TB
Internet((Internet)) --> ALB[Application Load Balancer]
ALB --> AZ1[AZ1: App via Auto Scaling]
ALB --> AZ2[AZ2: App via Auto Scaling]
AZ1 --> AUR[(Aurora Writer + Reader across AZs)]
AZ2 --> AUR
AZ1 --> NAT1[NAT Gateway AZ1]
AZ2 --> NAT2[NAT Gateway AZ2]
ภาพ Diagram
หัวข้อที่มีชื่อว่า “ภาพ Diagram”Diagram นี้เป็นภาพสรุปเพื่อช่วยทำความเข้าใจโครงสร้างของบท/แล็บ โดยยึดแนวคิดจากคู่มือต้นฉบับ คู่มือภาษาไทยสำหรับทำ Lab 4 จาก Architecting on AWS 7.12.4 Lab Guide
ช่วงต้นฉบับ: หน้า 69–93
คงชื่อ AWS Console menu / button / field / resource เป็น English ตาม Lab
เป้าหมาย
หัวข้อที่มีชื่อว่า “เป้าหมาย”ปรับสถาปัตยกรรม Web Application เดิมให้ High Availability มากขึ้น โดยทำดังนี้:
- ใช้ Launch Template + EC2 Auto Scaling
- รัน Application Tier ข้าม 2 Availability Zones
- เชื่อม Auto Scaling Group เข้ากับ Application Load Balancer
- เพิ่ม Aurora Reader คนละ Availability Zone
- เพิ่ม NAT Gateway ตัวที่สอง
- ทดสอบ Instance failure และ Aurora failover
Start Lab
หัวข้อที่มีชื่อว่า “Start Lab”- กด
Start Lab - รอ resource พร้อม
- กด
Open Console - ใช้ Region ที่ Lab กำหนด
Task 1 — Inspect your existing lab environment
หัวข้อที่มีชื่อว่า “Task 1 — Inspect your existing lab environment”Lab เตรียม resource หลักไว้แล้ว ได้แก่ VPC, Public/Private Subnets 2 AZs, Internet Gateway, NAT Gateway, Application Load Balancer, AppServer และ Aurora cluster
Task 1.1 — Examine the network infrastructure
หัวข้อที่มีชื่อว่า “Task 1.1 — Examine the network infrastructure”Search→VPCYour VPCs→ ตรวจLab VPCSubnets→ เลือกPublic Subnet 1- เปิด tab
Route table- ตรวจ route local ของ VPC
- ตรวจ
0.0.0.0/0ชี้ไป Internet Gateway
- เปิด tab
Network ACLเพื่อดู rule ที่ associate กับ subnet - เลือก
Internet gateways- ตรวจว่ามี Internet Gateway ชื่อ
Lab IGattach กับLab VPC
- ตรวจว่ามี Internet Gateway ชื่อ
- เลือก
Security groupsแล้วตรวจ:Inventory-ALB→ Inbound HTTP/80 จาก0.0.0.0/0Inventory-App→ Inbound HTTP/80 จาก security groupInventory-ALBInventory-DB→ Inbound MySQL/Aurora TCP/3306 จากInventory-App
Task 1.2 — Examine the EC2 instance
หัวข้อที่มีชื่อว่า “Task 1.2 — Examine the EC2 instance”Search→EC2Instances→ เลือกAppServerActions→Instance settings→Edit user data- กด
Copy user data - เก็บ User Data ไว้ใน text editor — จะใช้ตอนสร้าง Launch Template
Task 1.3 — Examine the load balancer configuration
หัวข้อที่มีชื่อว่า “Task 1.3 — Examine the load balancer configuration”Target Groups→ เลือกInventory-App- tab
Targets→ ตรวจว่าAppServerเป็น registered target Load Balancers→ เลือกInventory-LB
Task 1.4 — Open the PHP inventory application
หัวข้อที่มีชื่อว่า “Task 1.4 — Open the PHP inventory application”- Copy ค่า
InventoryAppSettingsPageURLจากหน้าคำสั่ง Lab - เปิด URL ใน browser tab ใหม่
- หน้า Settings จะมีค่า Database เดิมกรอกไว้แล้ว
- คงค่าทั้งหมดตาม default
- กด
Save - อย่าปิด tab Inventory Application เพราะจะใช้ทดสอบ Task ต่อไป
Task 2 — Create a launch template
หัวข้อที่มีชื่อว่า “Task 2 — Create a launch template”Search→EC2- Navigation pane →
Launch Templates - กด
Create launch template - ตั้งค่า:
Launch template name - required:Lab-Launch-templateTemplate version description:version 1
Application and OS Images (Amazon Machine Image)→Quick Start- เลือก
Amazon Linux - AMI:
Amazon Linux 2023 AMI Instance type:t3.micro- ใน
Network Settings:Security groups:Inventory-App
- เปิด
Advanced details IAM instance profile:Inventory-App-Role- ใน
User dataวาง User Data ที่ copy จากAppServerใน Task 1.2 - กด
Create launch template - กด
View launch templates
Task 3 — Create an Auto Scaling group
หัวข้อที่มีชื่อว่า “Task 3 — Create an Auto Scaling group”- Navigation pane →
Auto Scaling Groups - กด
Create Auto Scaling group - ตั้งค่า:
Auto Scaling group name:Inventory-ASGLaunch template: เลือกLab-Launch-template
- กด
Next - ใน
Network:VPC:Lab VPCAvailability Zones and subnets: เลือกPrivate Subnet 1และPrivate Subnet 2
- กด
Next - หน้า
Integrate with other services - optional:- เลือก
Attach to an existing load balancer - เลือก
Choose from your load balancer target groups Existing load balancer target groups:Inventory-App | HTTPHealth check grace period:300
- เลือก
- กด
Next - หน้า
Configure group size and scaling - optional:Desired capacity:2Min desired capacity:2Max desired capacity:2
- ที่
Additional settingsเปิดEnable group metrics collection within CloudWatch - กด
NextจนถึงAdd tags - optional Add tag:
Key:NameValue - optional:Inventory-App
- กด
Next - ตรวจ Summary แล้วกด
Create Auto Scaling group - เลือก
Inventory-ASGแล้วดู:
- tab
Activity - tab
Instance management
- รอให้ instance ใหม่ 2 ตัวเข้าสถานะ
InService
Task 4 — Test the application
หัวข้อที่มีชื่อว่า “Task 4 — Test the application”Target Groups→ เลือกInventory-App- tab
Targets - ตอนนี้ควรเห็น 3 targets:
AppServerเดิมInventory-Appจาก Auto Scaling 2 instances
- เลือก target
AppServer - กด
Deregister - ใน popup กด
Deregister - รอจนเหลือเฉพาะ
Inventory-Appสองตัว และทั้งคู่เป็นhealthy - กลับ browser tab ของ Inventory Application
- หากปิดไปแล้ว:
Load Balancers→Inventory-LB- Copy
DNS name - เปิดใน browser
- Refresh หน้าเว็บหลายครั้ง
- ดู Instance ID และ Availability Zone ด้านล่างของหน้า — ควรสลับไปมาระหว่างสอง EC2 instances / สอง AZs
Task 5 — Test high availability of the application tier
หัวข้อที่มีชื่อว่า “Task 5 — Test high availability of the application tier”จำลอง EC2 failure:
- กลับ
EC2→Instances - เลือก
Inventory-Appตัวใดตัวหนึ่ง Instance State→Terminate (delete) instance- ยืนยัน
Terminate (delete) - กลับไป Inventory Application และ Refresh หลายครั้ง
- Application ควรยังเปิดได้ เพราะ ALB ส่ง traffic ไป instance ที่เหลือ
- กลับหน้า
Instances - Refresh ทุกประมาณ 30 วินาทีจน Auto Scaling สร้าง
Inventory-Appตัวใหม่ขึ้นมา - รอ Status Check ของ instance ใหม่ผ่าน
- กลับ Inventory Application และ Refresh หลายครั้งอีกครั้ง
- ควรเห็น Instance ID / Availability Zone กลับมาสลับระหว่าง 2 instances
Task 6 — Configure high availability of the database tier
หัวข้อที่มีชื่อว่า “Task 6 — Configure high availability of the database tier”Task 6.1 — Configure the database across multiple Availability Zones
หัวข้อที่มีชื่อว่า “Task 6.1 — Configure the database across multiple Availability Zones”Search→Aurora and RDS- Navigation pane →
Databases - หา
inventory-primary - ดู column
Region & AZแล้วจด AZ ของ primary ไว้ - เลือก cluster
inventory-cluster Actions→Add reader- ใน
Settings:DB instance identifier:inventory-replica
- ใน
Connectivity:Availability Zone: เลือก AZ ที่ ต่างจากinventory-primary
- ใน
Monitoring:- เอาเครื่องหมายออกจาก
Enable Enhanced monitoring
- เอาเครื่องหมายออกจาก
- กด
Add reader inventory-replicaจะขึ้นCreating— สามารถไป Task 7 ต่อได้โดยไม่ต้องรอ
Task 7 — Make the NAT gateway highly available
หัวข้อที่มีชื่อว่า “Task 7 — Make the NAT gateway highly available”Task 7.1 — Create a second NAT gateway
หัวข้อที่มีชื่อว่า “Task 7.1 — Create a second NAT gateway”Search→VPC- Navigation pane →
NAT gateways - กด
Create NAT gateway - ตั้งค่า:
Name - optional:my-nat-gatewayAvailability mode:ZonalSubnet:Public Subnet 2
- กด
Allocate Elastic IP - กด
Create NAT gateway
Task 7.2 — Create and configure a new route table
หัวข้อที่มีชื่อว่า “Task 7.2 — Create and configure a new route table”- Navigation pane →
Route tables - กด
Create route table - ตั้งค่า:
Name - optional:Private Route Table 2VPC:Lab VPC
- กด
Create route table Routes→Edit routesAdd route:Destination:0.0.0.0/0Target:NAT Gateway→my-nat-gateway
- กด
Save changes
Task 7.3 — Configure routing for Private Subnet 2
หัวข้อที่มีชื่อว่า “Task 7.3 — Configure routing for Private Subnet 2”- tab
Subnet associations - กด
Edit subnet associations - เลือก
Private Subnet 2 - กด
Save associations
ตอนนี้ Private Subnet 2 ออก Internet ผ่าน NAT Gateway ใน AZ เดียวกัน ไม่ต้องพึ่ง NAT Gateway ของ AZ แรก
Task 8 — Force a failover of the Aurora database
หัวข้อที่มีชื่อว่า “Task 8 — Force a failover of the Aurora database”Search→Aurora and RDSDatabases- รอจน
inventory-replicaเป็นAvailable - เลือก
inventory-primary - ตรวจ column
Roleว่า primary เป็นWriter Actions→Failover- หน้า
Failover DB Cluster→ กดFailover inventory-clusterจะเข้าสถานะFailing over- Navigation pane →
Events - ดู event ระหว่าง failover
- Aurora จะ promote Reader ให้เป็น Writer ใหม่ และ reboot instance ตามลำดับ
- ทดสอบ Inventory Application — ระบบควรยังใช้งานได้หลัง failover
End Lab
หัวข้อที่มีชื่อว่า “End Lab”- กลับ
AWS Management Console AWSLabsUser→Sign out- กลับหน้า Lab →
End Lab - ยืนยัน
Architecture หลังจบ Lab
หัวข้อที่มีชื่อว่า “Architecture หลังจบ Lab” Internet ↓ Application Load Balancer / \ Private Subnet 1 Private Subnet 2 Inventory-App Inventory-App \ / Aurora Cluster Writer + Reader (2 AZs)
Public Subnet 1 Public Subnet 2NAT Gateway my-nat-gateway ↑ ↑Private Subnet 1 Private Subnet 2ผลที่ต้องได้คือ Application Tier, Database Tier และ outbound path ของ private subnets มี redundancy ข้าม Availability Zones
↩️ กลับไป Activity หลัก
หัวข้อที่มีชื่อว่า “↩️ กลับไป Activity หลัก”หน้านี้เป็นเนื้อหาเสริมหรือ Companion Lab ใช้ประกอบบทเหล่านี้ได้: