Systems Manager Automation
AWS Systems Manager ช่วยจัดการ instances และ managed nodes โดยลดการพึ่งพา SSH, bastion hosts และ manual commands ที่ไม่มี audit trail
Session Manager
Session Manager ให้เชื่อมต่อ EC2 หรือ managed nodes ผ่าน browser/CLI โดยไม่ต้องเปิด inbound SSH port หรือจัดการ SSH keys ควรเปิด session logging ไป CloudWatch Logs หรือ S3 และควบคุม access ด้วย IAM
aws ssm start-session --target i-0123456789abcdef0
Run Command
Run Command ใช้สั่ง commands ไปยัง managed nodes แบบ remote และ auditable เหมาะกับงาน bootstrap, diagnostic, log collection หรือ one-time configuration changes ที่ต้องทำหลายเครื่อง
aws ssm send-command \
--document-name "AWS-RunShellScript" \
--targets "Key=tag:Environment,Values=dev" \
--parameters 'commands=["uptime","df -h"]'
Patch Manager
Patch Manager ช่วย automate patching process ของ managed nodes ผ่าน patch baselines และ maintenance windows ใช้ลด drift และทำให้ patch compliance ตรวจสอบได้
Automation Document
Automation Document หรือ runbook กำหนดขั้นตอน automation เช่น snapshot volume, restart service, update AMI หรือ rollback action โดยมี inputs, approvals และ execution history
Best practices
- ปิด inbound SSH เมื่อ Session Manager พร้อมใช้งาน
- ใช้ IAM condition จำกัดว่าใคร start session ไป instance ใดได้
- เปิด CloudTrail และ session logs สำหรับ audit
- ใช้ VPC Endpoints สำหรับ SSM ใน private subnets เมื่อต้องการไม่ออก Internet
- ทดสอบ Automation Document ใน dev ก่อนใช้กับ production
Common mistakes
- ติดตั้ง SSM Agent แต่ไม่ให้ instance profile permission ที่ต้องใช้
- ไม่เปิด logs ทำให้ตรวจไม่ได้ว่าใครทำอะไรใน session
- ใช้ Run Command ยิงคำสั่งกว้างเกินไปโดยไม่มี target tags และ approval
Review questions
- Session Manager ช่วยลดความเสี่ยงจาก SSH อย่างไร?
- Run Command เหมาะกับงานแบบใด?
- Patch Manager และ Automation Document ต่างกันอย่างไร?