AWS Account Setup
AWS Account เป็น boundary ใหญ่ที่สุดของ Resource และ Billing ใน Phase นี้ต้องตั้งค่า Account ให้ปลอดภัยก่อนทำ Lab อื่น: เปิด MFA, หลีกเลี่ยง Root User, ใช้ IAM Identity Center หรือ IAM User อย่างระมัดระวัง และตรวจ Identity ด้วย AWS CLI
aws sts get-caller-identity ลดโอกาสรันผิด account หรือผิด role
Root User
Root User ถูกสร้างพร้อม AWS Account และมีสิทธิ์สูงสุด ใช้สำหรับงานจำเป็นบางอย่างเท่านั้น เช่น ตั้งค่า Account-level หรือ Recovery บางกรณี ไม่ควรใช้ Root User ทำงานประจำหรือสร้าง Access Key
- ใช้อีเมลที่ควบคุมโดยเจ้าของ Account หรือองค์กร
- เปิด MFA ทันที
- ไม่สร้าง Root Access Key
- เก็บ recovery information ให้ปลอดภัย
IAM Identity Center หรือ IAM User
สำหรับผู้ใช้จริงในองค์กร ควรใช้ IAM Identity Center เพื่อให้ Login ผ่าน SSO และรับ temporary role session แทนการสร้าง IAM User พร้อม credential ระยะยาว แต่ใน Account เรียนส่วนตัวอาจใช้ IAM User ได้ถ้าจำเป็น โดยต้องเปิด MFA และจำกัด Permission
AWS CLI และ Profile
AWS CLI เป็นเครื่องมือเรียก AWS API จาก Terminal ใช้เพื่อทดสอบ Identity, Automation และต่อยอดไป Infrastructure as Code
ควรแยก Profile ตาม Account หรือ Environment เช่น dev, staging, prod
aws configure --profile learning
aws sts get-caller-identity --profile learning
คำสั่ง aws sts get-caller-identity คืนค่า UserId, Account และ Arn
ของ IAM identity ที่ credential ปัจจุบันใช้อยู่ จึงเหมาะสำหรับตรวจว่าคุณกำลังทำงานใน Account และ Role ที่ถูกต้อง
Best practices
- ใช้ Least Privilege: ให้สิทธิ์เท่าที่ต้องใช้ ไม่ให้สิทธิ์เผื่อ
- ใช้ temporary credentials ผ่าน Role เมื่อทำได้
- แยก Profile และตรวจ
Accountก่อนรันคำสั่งที่สร้างหรือลบ Resource - ตั้งค่า default output เป็น
jsonเพื่อให้ Automation อ่านง่าย
Common mistakes
- ใช้ Root User ทำทุกอย่างเพราะตั้งค่าง่าย
- ใช้ Access Key เดียวกันในหลายเครื่อง หลาย Project และไม่ rotate
- ลืมตรวจ Profile ก่อนรันคำสั่งใน Account จริง
Review questions
- Root user เปิด MFA แล้ว และไม่ได้ใช้ทำงานประจำ
- มี identity สำหรับเรียนที่ไม่ใช่ root พร้อม permission ที่เหมาะสม
- รัน
aws sts get-caller-identityแล้วอ่าน Account/Arn ได้
- ทำไมไม่ควรใช้ Root User ทำงานประจำ?
aws sts get-caller-identityช่วยลดความเสี่ยงอะไร?- IAM Identity Center ช่วยลดการใช้ credential ระยะยาวอย่างไร?