ระดับ 2 · บทที่ 1/5

เปิดบัญชี AWS ให้ปลอดภัยตั้งแต่วันแรก

⏱ 45 นาทีลองในAWS Console ↗
ข้อมูลบางส่วนอาจเปลี่ยน — ตรวจสอบก่อนใช้

บทนี้มีข้อมูลที่เปลี่ยนบ่อย (ฟีเจอร์ ราคา ชื่อเมนู) ตรวจกับเว็บทางการก่อนนำไปใช้

เป้าหมาย

จบบทนี้คุณจะมีบัญชี AWS ที่ (1) root มี MFA และแทบไม่ได้ใช้อีก (2) มีผู้ใช้ประจำวันใน IAM Identity Center ที่ล็อกอินแบบ MFA (3) มี budget alert ส่งอีเมลเมื่อค่าใช้จ่ายเริ่มขยับ และ (4) ไม่มี access key ถาวรแม้แต่ตัวเดียว

ผู้ใช้ 3 แบบใน AWS

แบบ คืออะไร ใช้เมื่อ
root user อีเมลที่ใช้สมัคร ทำได้ทุกอย่าง จำกัดสิทธิ์ไม่ได้ งานไม่กี่อย่าง เช่น เปลี่ยนแผน/ปิดบัญชี — นอกนั้นห้ามใช้
IAM user ผู้ใช้ในบัญชีเดียว มักมี access key ถาวร ระบบเก่า — หลักสูตรนี้ไม่ใช้
IAM Identity Center user ผู้ใช้กลาง ล็อกอินผ่าน access portal ได้สิทธิ์ผ่าน permission set และได้คีย์ชั่วคราวให้ CLI งานประจำวันทั้งหมด ✅

ทำไม Identity Center: คีย์ที่ CLI ได้รับหมดอายุเอง ถ้าหลุดก็ใช้ได้ไม่นาน และเพิ่มบัญชี AWS อื่นภายหลัง (ระดับสาย AWS) ได้จากที่เดียว

ก่อนเริ่ม: Free plan หรือ Paid plan

บัญชีใหม่เลือกได้ตอนสมัคร ทั้งสองแบบได้เครดิตเริ่มต้นเหมือนกัน แต่:

  • IAM Identity Center แบบที่ให้สิทธิ์เข้าบัญชี AWS ได้ ต้องเป็น "organization instance" ซึ่งสร้าง AWS Organizations ให้อัตโนมัติ
  • บัญชี Free plan ที่สร้าง Organizations จะถูกอัปเกรดเป็น Paid plan อัตโนมัติ (ใช้เกินเครดิตเก็บเงินจริง)
  • หลักสูตรนี้จึงแนะนำ Paid plan + budget alert ตั้งแต่ต้น เพราะสาย AWS ระดับถัดไปต้องใช้ Organizations อยู่แล้ว

⚠️ ต้องตรวจสอบ: เอกสาร IAM Identity Center ระบุว่าเครดิต free tier "หมดอายุทันที" เมื่อบัญชี Free plan สร้าง organization ขณะที่หน้า Free plan ระบุว่าการอัปเกรดเองจะยกเครดิตที่เหลือไปใช้ต่อ — อ่านข้อความเตือนบนหน้าจอให้ดีก่อนกด Enable และดูยอดเครดิตใน Billing ก่อน/หลัง

ถ้าอยากอยู่บน Free plan ต่อ: ข้ามส่วน Identity Center ไปก่อน ใช้ IAM user ที่มีแค่รหัสผ่าน console + MFA (ไม่สร้าง access key) แนบ policy AdministratorAccess และ SignInLocalDevelopmentAccess แล้วใช้ aws login ในบท 03 แทน ค่อยกลับมาทำ Identity Center เมื่อพร้อม

ขั้นที่ 1 — ล็อก root

  1. สมัครที่ aws.amazon.com ใช้อีเมลที่ไม่ใช่อีเมลส่วนตัวหลัก ถ้าทำได้ (เช่น alias [email protected]) และรหัสผ่านยาวจากตัวจัดการรหัสผ่าน
  2. ล็อกอินแบบ Root user → มุมขวาบนคลิกชื่อบัญชี → Security credentials → Assign MFA device
  3. เลือก Passkey or security key (ดีที่สุด) หรือ Authenticator app — ลงทะเบียนอย่างน้อย 2 อุปกรณ์เผื่อหาย
  4. ในหน้าเดียวกัน ตรวจว่าหัวข้อ Access keys ว่าง — root ห้ามมี access key
  5. ตั้ง Alternate contacts (Billing, Security) ในหน้า Account เพื่อให้แจ้งเตือนสำคัญไม่ตกหล่น

ขั้นที่ 2 — budget alert (ทำก่อนสร้างอะไร)

Console → Billing and Cost Management → Budgets → Create budget → ใช้ template Zero spend budget (เตือนทันทีที่มีค่าใช้จ่ายเกิน $0.01) และสร้างอีกอัน Monthly cost budget เช่น $5

⚠️ ต้องตรวจสอบ: budget แบบแจ้งเตือนอย่างเดียวใช้ได้โดยไม่เสียเงินในจำนวนที่ AWS กำหนด ดูหน้า AWS Budgets pricing ก่อนสร้างหลายอัน · budget ไม่หยุดค่าใช้จ่ายให้ มันแค่ส่งอีเมล

ขั้นที่ 3 — เปิด IAM Identity Center และสร้างผู้ใช้

  1. เลือก region ที่จะใช้ประจำ (หลักสูตรนี้ใช้ ap-southeast-1 สิงคโปร์) ก่อน เปิด — เปลี่ยน region ทีหลังต้องลบแล้วสร้างใหม่
  2. Console → ค้นหา IAM Identity Center → Enable → ยืนยันหน้า Enable IAM Identity Center with AWS Organizations
  3. Users → Add user → ใส่ username, อีเมล (อีเมลจริงของคุณ), ชื่อ → ระบบส่งอีเมลเชิญให้ตั้งรหัสผ่าน
  4. Permission sets → Create permission set → Predefined → AdministratorAccess → ตั้ง Session duration เช่น 4 ชั่วโมง
  5. AWS accounts → ติ๊กบัญชีของคุณ → Assign users or groups → เลือกผู้ใช้ + permission set
  6. Settings → Authentication → ตรวจว่าบังคับ MFA สำหรับผู้ใช้ (ให้ลงทะเบียนตอนล็อกอินครั้งแรก)
  7. คัดลอก AWS access portal URL (หน้าตา https://d-xxxxxxxxxx.awsapps.com/start) เก็บไว้ — ใช้ในบท 03
  8. ออกจาก root แล้วล็อกอินผ่าน portal URL ด้วยผู้ใช้ใหม่ ตั้งรหัสผ่าน + MFA

AdministratorAccess ใช้สำหรับบัญชีเรียนของคุณคนเดียวเท่านั้น ระดับ 3a จะสอนตัดสิทธิ์ให้แคบลง (least privilege)

ลองเลย 🧪

ทำหลังติดตั้ง AWS CLI (บท 03) ได้ หรือเปิด CloudShell (ไอคอน >_ บนแถบบนของ console) ซึ่งล็อกอินมาให้แล้ว

ทดลอง A — ฉันเป็นใคร

aws sts get-caller-identity

ผลที่ควรเห็น (เมื่อเข้าผ่าน Identity Center):

{
    "UserId": "AROAEXAMPLEID:you",
    "Account": "111122223333",
    "Arn": "arn:aws:sts::111122223333:assumed-role/AWSReservedSSO_AdministratorAccess_abcdef1234567890/you"
}

→ คำว่า assumed-role/AWSReservedSSO_... = ใช้สิทธิ์ชั่วคราวผ่าน permission set ถูกต้อง · ถ้าเห็น :root แปลว่ายังใช้ root อยู่ — ออกแล้วเข้าใหม่

ทดลอง B — ตรวจว่า root มี MFA และไม่มีคีย์

aws iam get-account-summary \
  --query 'SummaryMap.{RootMFA:AccountMFAEnabled,RootAccessKeys:AccountAccessKeysPresent,IAMUsers:Users}'

ผลที่ควรเห็น:

{
    "RootMFA": 1,
    "RootAccessKeys": 0,
    "IAMUsers": 0
}

→ ต้องเป็น 1 / 0 / 0 · ถ้า RootAccessKeys เป็น 1 ให้ลบคีย์ของ root ทันทีที่ Security credentials

ทดลอง C — สร้าง budget ด้วย CLI (ถ้ายังไม่ได้สร้างใน console) · แก้ [อีเมลของคุณ] ทั้ง 2 ที่ก่อนรัน · ถ้ารันบนเครื่องตัวเองหลังบท 03 ให้ export AWS_PROFILE=learn ก่อน (ใน CloudShell ไม่ต้อง)

ACCOUNT_ID=$(aws sts get-caller-identity --query Account --output text)
cat > budget.json <<'EOF'
{
  "BudgetName": "cloud-ladder-monthly-5usd",
  "BudgetLimit": { "Amount": "5", "Unit": "USD" },
  "BudgetType": "COST",
  "TimeUnit": "MONTHLY"
}
EOF
cat > notifications.json <<'EOF'
[
  {
    "Notification": { "NotificationType": "ACTUAL", "ComparisonOperator": "GREATER_THAN",
                      "Threshold": 20, "ThresholdType": "PERCENTAGE" },
    "Subscribers": [ { "SubscriptionType": "EMAIL", "Address": "[อีเมลของคุณ]" } ]
  },
  {
    "Notification": { "NotificationType": "FORECASTED", "ComparisonOperator": "GREATER_THAN",
                      "Threshold": 100, "ThresholdType": "PERCENTAGE" },
    "Subscribers": [ { "SubscriptionType": "EMAIL", "Address": "[อีเมลของคุณ]" } ]
  }
]
EOF
aws budgets create-budget --account-id "$ACCOUNT_ID" \
  --budget file://budget.json --notifications-with-subscribers file://notifications.json
aws budgets describe-budgets --account-id "$ACCOUNT_ID" \
  --query 'Budgets[].[BudgetName,BudgetLimit.Amount,BudgetLimit.Unit]' --output text
rm budget.json notifications.json      # ไฟล์ชั่วคราว (มีอีเมลของคุณ) ไม่ต้องเก็บ

ผลที่ควรเห็น:

cloud-ladder-monthly-5usd	5.0	USD

→ แจ้งเตือนเมื่อใช้จริงเกิน 20% ($1) และเมื่อคาดว่าทั้งเดือนจะเกิน $5 · create-budget สำเร็จจะไม่พิมพ์อะไร ถ้าพัง: DuplicateRecordException → มีชื่อนี้แล้ว · AccessDeniedException → ยังไม่ได้เปิดสิทธิ์ Billing ให้ผู้ใช้ IAM (ใช้ Identity Center + AdministratorAccess จะไม่เจอ)

ทดลอง D — ดูว่ามี access key ถาวรหลงอยู่ไหม

aws iam list-users --query 'Users[].UserName' --output text
for u in $(aws iam list-users --query 'Users[].UserName' --output text); do
  aws iam list-access-keys --user-name "$u" --query 'AccessKeyMetadata[].[UserName,AccessKeyId,Status]' --output text
done

ผลที่ควรเห็น: ว่างเปล่า (ไม่มี IAM user และไม่มีคีย์) — ถ้าเลือกเส้นทาง Free plan + IAM user จะเห็นชื่อผู้ใช้ 1 คนแต่ต้องไม่มีคีย์

กับดักที่เจอบ่อย

อาการ สาเหตุ / แก้
เปิด Identity Center แล้วไม่เห็นเมนู AWS accounts เปิดเป็น account instance (ไม่รองรับ permission set) ต้องเป็น organization instance
ผู้ใช้ใหม่ล็อกอินแล้วไม่เห็นบัญชีใดเลย ยังไม่ได้ assign ผู้ใช้ + permission set ให้บัญชี (ขั้นที่ 3 ข้อ 5)
หาผู้ใช้ที่สร้างไว้ไม่เจอ อยู่คนละ region — Identity Center อยู่ region เดียวที่เปิดไว้
ไม่ได้รับอีเมล budget อีเมลไปอยู่ใน spam, พิมพ์อีเมลผิด หรือยังไม่มีค่าใช้จ่ายถึงเกณฑ์ (budget ส่งเมื่อถึงเกณฑ์เท่านั้น)
ทำ MFA หายแล้วเข้า root ไม่ได้ ลงทะเบียน MFA 2 อุปกรณ์ตั้งแต่แรก กู้คืนต้องผ่านขั้นตอนยืนยันตัวตนของ AWS ซึ่งใช้เวลา
สร้าง access key "ไว้ใช้แป๊บเดียว" ไม่จำเป็นอีกแล้ว — aws sso login ให้คีย์ชั่วคราวแทน

สรุปจำง่าย

root: MFA 2 อุปกรณ์ ไม่มีคีย์ ไม่ใช้งานประจำ — budget alert ก่อนสร้างอะไร — งานประจำวันผ่าน IAM Identity Center + MFA — Organizations ทำให้ Free plan กลายเป็น Paid plan จึงต้องมี budget — get-caller-identity ต้องเห็น AWSReservedSSO_ ไม่ใช่ root