Lab 1: Account, CLI และ Budget Baseline
Lab นี้สร้างพื้นฐานก่อนทำ AWS Infrastructure จริง: Login ด้วย Identity ที่ไม่ใช่ Root, ตรวจ AWS CLI identity, ตั้ง AWS Budget และกำหนด Tagging convention สำหรับ Lab ถัดไป
Goal
ยืนยันว่าทำงานด้วย identity ที่ถูกต้อง
ตรวจ Console session และ AWS CLI caller identity ก่อนสร้าง resource ใด ๆ
Guardrail
Budget รายเดือนพร้อม threshold
ตั้ง 50%, 80%, 100% actual spend และ forecasted notification
Output
Profile, Budget, Tag convention
สิ่งเหล่านี้จะถูกใช้ซ้ำใน Phase ถัดไป ไม่ใช่แค่จบใน Lab นี้
Run order
- Login ด้วย identity ที่ไม่ใช่ root
- Configure AWS CLI profile แล้วตรวจ caller identity
- สร้าง Budget และ notification
- บันทึก tagging convention
- ตรวจ verification checklist ก่อน mark lab complete
Learning objectives
- ตรวจว่าใช้งาน AWS Account ด้วย Identity ที่ปลอดภัยกว่า Root User
- ตั้งค่า AWS CLI Profile และยืนยัน Account ด้วย
aws sts get-caller-identity - สร้าง AWS Budget พร้อม Notification
- กำหนด Tagging convention สำหรับ Resource ใน Lab ถัดไป
Prerequisites
- AWS Account ที่เปิด MFA สำหรับ Root User แล้ว
- IAM Identity Center หรือ IAM User สำหรับเรียน
- AWS CLI v2 ติดตั้งบนเครื่อง
- Email ที่รับ Budget notification ได้
Cost note: Lab นี้ไม่จำเป็นต้องสร้าง Compute หรือ Database แต่ Budget notification อาจมี delay
หลังเกิดค่าใช้จ่ายจริง จึงต้องตรวจ Console และ cleanup resource จาก Lab อื่นเสมอ
Step 1: Login ด้วย Identity ที่ไม่ใช่ Root
- เข้า AWS Management Console
- Login ด้วย IAM Identity Center หรือ IAM User ที่เตรียมไว้
- ตรวจว่ามี MFA หรือ SSO session ที่เหมาะสม
- หลีกเลี่ยงการใช้ Root User ยกเว้นงาน Account-level ที่จำเป็น
Expected result: คุณอยู่ใน Console ด้วย Identity สำหรับงานประจำ ไม่ใช่ Root User
Step 2: Configure AWS CLI Profile
aws configure --profile learning
กรอกค่า Access Key, Secret Access Key, default Region และ output format ตาม Credential ที่เตรียมไว้
Default region name [None]: ap-southeast-1
Default output format [None]: json
Step 3: Verify caller identity
aws sts get-caller-identity --profile learning
ผลลัพธ์ควรมีโครงสร้างประมาณนี้:
{
"UserId": "AIDASAMPLEUSERID",
"Account": "123456789012",
"Arn": "arn:aws:iam::123456789012:user/learning-user"
}
Step 4: Create AWS Budget
- เปิด Billing and Cost Management Console
- ไปที่ Budgets แล้วเลือก Create budget
- เลือก Cost budget
- ตั้ง Period เป็น Monthly
- กำหนด Amount เช่น 5 USD หรือค่าที่เหมาะกับการเรียน
- เพิ่ม Notification ที่ 50%, 80% และ 100% ของ actual spend
- เพิ่ม forecasted notification อย่างน้อยที่ 80%
- ใส่ Email ผู้รับแจ้งเตือนและยืนยัน Email ถ้าระบบร้องขอ
Step 5: Define Tagging convention
บันทึก convention นี้ไว้ใช้ใน Lab ถัดไป:
Environment = learning
Owner = your-name
Project = aws-infra-learning
ManagedBy = manual-lab
Verification steps
Definition of done
aws sts get-caller-identity --profile learningแสดง Account ID ถูกต้อง- AWS Budgets แสดง Budget รายเดือนที่สร้างไว้
- Notification มี Email ถูกต้องและ Threshold ครบ
- คุณมี Tagging convention ที่จะใช้ซ้ำใน Phase ถัดไป
Troubleshooting
| อาการ | แนวทางแก้ |
|---|---|
Unable to locate credentials | ตรวจว่าใช้ --profile learning และเคยรัน aws configure --profile learning แล้ว |
AccessDenied | ตรวจ Permission ของ Identity หรือใช้ Identity ที่มีสิทธิ์ดู Billing/Budget |
| ไม่เห็น Billing Console | ตรวจว่ามีสิทธิ์ Billing และเปิด IAM access to billing information ตามรูปแบบ Account |
| ไม่ได้รับ Email แจ้งเตือน | ตรวจ Email, spam folder และสถานะ verification/subscription ถ้ามี SNS เกี่ยวข้อง |
Cleanup procedures
Lab นี้ไม่สร้าง Compute, Database หรือ Network resource จึงไม่มี Resource ที่ต้องลบเพื่อหยุดค่าใช้จ่าย แต่ถ้าสร้าง Budget ทดลองหลายตัว ให้ลบ Budget ที่ไม่ใช้เพื่อไม่ให้เกิดความสับสน
Mini quiz
- ทำไมต้องตรวจ
AccountและArnก่อนทำ Lab ที่สร้าง Resource? - Budget actual notification กับ forecasted notification ต่างกันอย่างไร?
- Tag
EnvironmentและOwnerช่วย Operation อย่างไร?