Lesson 4 Cost guardrail

Cost Management

AWS คิดค่าใช้จ่ายแบบ Pay-as-you-go จึงเหมาะกับการทดลอง แต่ต้องมี guardrail ตั้งแต่เริ่ม: AWS Budgets, Billing Alert, Cost Explorer และ Tagging convention คือเครื่องมือพื้นฐานที่ควรทำก่อนสร้าง Resource จำนวนมาก

Pricing habit คิดค่าใช้จ่ายก่อน deploy Free Tier ไม่ครอบคลุมทุก service, region, size หรือ data transfer
Guardrail Budget + notification ตั้ง actual และ forecasted threshold เพื่อรู้ตัวก่อนค่าใช้จ่ายเกินแผน
Visibility Tag ทุก resource ที่รองรับ ใช้ Owner, Environment, Project และ ManagedBy เพื่อแยกต้นทุนและ cleanup

Pay-as-you-go และ Free Tier

Pay-as-you-go หมายถึงจ่ายตามการใช้งานจริง เช่น ชั่วโมงของ EC2, ขนาด Storage, จำนวน Request หรือ Data transfer Free Tier ช่วยลดค่าใช้จ่ายช่วงเริ่มต้น แต่ไม่ได้ครอบคลุมทุก Service, ทุก Region หรือทุกขนาด Resource

ข้อควรระวัง: NAT Gateway, Elastic IP ที่ไม่ได้ attach, Load Balancer, RDS, Data transfer และ Log retention เป็นตัวอย่างที่ทำให้เกิดค่าใช้จ่ายได้แม้เป็น Lab

AWS Budgets

AWS Budgets ใช้ติดตาม Cost และ Usage พร้อมตั้ง Notification เมื่อค่าใช้จ่ายจริงหรือค่าใช้จ่ายคาดการณ์เข้าใกล้ Threshold เช่นแจ้งเตือนเมื่อใช้ถึง 50%, 80% และ 100% ของ Budget รายเดือน

Budget ไม่ใช่ระบบปิด Resource อัตโนมัติในทุกกรณี และข้อมูล Billing อาจมี delay ดังนั้นควรใช้คู่กับนิสัยลบ Resource หลัง Lab และตรวจ Cost Explorer เป็นประจำ

Cost Explorer

Cost Explorer ใช้ดูแนวโน้มค่าใช้จ่าย แยกตาม Service, Region, Linked Account หรือ Tag ช่วยตอบคำถามว่า ค่าใช้จ่ายมาจากอะไรและเพิ่มขึ้นตั้งแต่เมื่อไร

Tagging convention

Tag ช่วยแยก Owner, Environment, Project และ Cost allocation ตัวอย่าง convention สำหรับ Lab:

Environment = learning
Owner       = your-name
Project     = aws-infra-learning
ManagedBy   = manual-lab

Best practices

  • ตั้ง Budget ก่อนเริ่มสร้าง Resource
  • เปิด Notification ทั้ง actual และ forecasted spend
  • ใช้ Tag กับ Resource ทุกตัวที่รองรับ
  • กำหนด cleanup checklist ในทุก Lab
  • ตรวจ Cost Explorer หลัง Lab ที่สร้าง Resource ราคาแพง

Review questions

Before lab
  1. เข้าใจว่า Budget alert มี billing delay และไม่ใช่ auto-shutdown ทุกกรณี
  2. รู้ service ที่มักทำให้ lab มีค่าใช้จ่าย เช่น NAT Gateway, ALB, RDS และ logs
  3. มี tagging convention ที่จะใช้ซ้ำใน lab ถัดไป
  1. ทำไม Budget Alert อาจแจ้งเตือนช้ากว่าค่าใช้จ่ายจริง?
  2. Tag ใดบ้างที่ควรมีใน Account สำหรับเรียน?
  3. Service ใดใน Lab ที่ควรระวังค่าใช้จ่ายเป็นพิเศษ?