AWS Learning
Monitoring & Management

AWS Systems Manager (SSM)

Run Command, Session Manager, Patch Manager, Parameter Store, Automation

Tổng quan

AWS Systems Manager (SSM) là dịch vụ giúp bạn quản lý tập trung nodes (EC2, on-premises, multicloud) ở quy mô lớn.

┌─────────────────────────────────────────────────────────────────────────────┐
│                        AWS Systems Manager                                  │
├─────────────────────────────────────────────────────────────────────────────┤
│                                                                             │
│   ┌─────────────────────────────────────────────────────────────────────┐   │
│   │                    Managed Nodes                                    │   │
│   │                                                                     │   │
│   │   ┌──────────┐    ┌──────────┐    ┌──────────┐    ┌──────────┐      │   │
│   │   │   EC2    │    │   EC2    │    │On-Premise│    │Multicloud│      │   │
│   │   │Instance  │    │Instance  │    │  Server  │    │   VM     │      │   │
│   │   │          │    │          │    │          │    │          │      │   │
│   │   │SSM Agent │    │SSM Agent │    │SSM Agent │    │SSM Agent │      │   │
│   │   └────┬─────┘    └────┬─────┘    └────┬─────┘    └────┬─────┘      │   │
│   │        │               │               │               │            │   │
│   └────────┼───────────────┼───────────────┼───────────────┼────────────┘   │
│            │               │               │                 │              │
│            └───────────────┴───────────────┴───────────────┘                │
│                                     │                                       │
│                                    ▼                                        │
│            ┌─────────────────────────────────────────────────┐              │
│            │           AWS Systems Manager                   │              │
│            │                                                 │              │
│            │  • Run Command      • Session Manager           │              │
│            │  • Patch Manager    • Parameter Store           │              │
│            │  • Automation       • State Manager             │              │
│            │  • Inventory        • Maintenance Windows       │              │
│            └─────────────────────────────────────────────────┘              │
│                                                                             │
└─────────────────────────────────────────────────────────────────────────────┘

SSM Agent

SSM Agent là phần mềm cài trên nodes để cho phép Systems Manager quản lý.

AspectChi tiết
Cài đặtPre-installed trên nhiều AMIs (Amazon Linux, Windows Server)
Yêu cầuCần IAM role với permissions cho SSM
Hỗ trợEC2, on-premises, edge devices, multicloud VMs
Để node trở thành "Managed Node":
  1. Cài SSM Agent
  2. Attach IAM Role với AmazonSSMManagedInstanceCore policy
  3. Agent có thể kết nối với SSM service (network connectivity)

SSM Agent hoạt động như thế nào?

┌───────────────────────────────────────────────────────────────────────────────┐
│                    SSM Agent - Cách hoạt động                                 │
├───────────────────────────────────────────────────────────────────────────────┤
│                                                                               │
│   ⚠️ QUAN TRỌNG: Agent KHÔNG lắng nghe connections!                           │
│   Agent CHỦ ĐỘNG gọi RA NGOÀI đến SSM Service                                 │
│                                                                               │
│   ┌─────────────────────┐                                                     │
│   │   AWS SSM Service   │  ← "Trung tâm điều khiển" ở cloud                   │
│   │   (trên cloud)      │                                                     │
│   └──────────▲──────────┘                        p                            │
│               │                                                               │
│              │  WebSocket (Agent GỌI RA, giữ connection)                      │
│               │                                                               │
│   ┌──────────┴──────────┐                                                     │
│   │   SSM Agent         │  ← Phần mềm TRONG EC2                               │
│   │   (trong EC2)       │     Gọi ra SSM Service, nhận lệnh, thực hiện        │
│   └─────────────────────┘                                                     │
│                                                                               │
│   Workflow:                                                                   │
│   1. Agent connect RA NGOÀI đến SSM Service (WebSocket)                       │
│   2. Giữ connection, chờ commands/sessions                                    │
│   3. Khi có command → Thực hiện và trả kết quả                                │
│                                                                               │
└───────────────────────────────────────────────────────────────────────────────┘

Agent có sẵn hay phải cài?

AMISSM Agent
Amazon Linux 2/2023✅ Có sẵn, đang chạy
Windows Server 2016+✅ Có sẵn
Ubuntu 16.04+ (AWS AMIs)✅ Có sẵn
On-premises servers❌ Phải cài thủ công
Custom AMIs⚠️ Có thể chưa có

[!NOTE] Agent có sẵn ≠ SSM hoạt động. Cần thêm IAM Rolenetwork connectivity!

Network Connectivity cho SSM Agent

Agent cần ĐƯỜNG ĐI để gọi ra SSM Service. Có 2 options:

┌──────────────────────────────────────────────────────────────────────────────┐
│                  Network Options cho SSM Agent                               │
├──────────────────────────────────────────────────────────────────────────────┤
│                                                                              │
│   OPTION 1: Qua Internet                                                     │
│   ────────────────────────                                                   │
│   EC2 ──► NAT Gateway ──► Internet ──► SSM Service                           │
│                                                                              │
│   Yêu cầu: EC2 có internet access (IGW hoặc NAT Gateway)                     │
│   Cost: NAT Gateway ~$32/tháng + data transfer                               │
│                                                                              │
│   ─────────────────────────────────────────────────────────────────────────  │
│                                                                              │
│   OPTION 2: Qua VPC Endpoints (Private - không cần internet)                 │
│   ───────────────────────────────────────────────────────────                │
│   EC2 ──► VPC Endpoint ──► SSM Service (qua AWS PrivateLink)                 │
│                                                                              │
│   Yêu cầu: Tạo 3 Interface Endpoints (BẠN TỰ TẠO, AWS không tự tạo!)         │
│   • com.amazonaws.{region}.ssm                                               │
│   • com.amazonaws.{region}.ssmmessages                                       │
│   • com.amazonaws.{region}.ec2messages                                       │
│                                                                              │
│   Cost: ~$0.01/hour/endpoint/AZ                                              │
│                                                                              │
└──────────────────────────────────────────────────────────────────────────────┘
ScenarioDùng gì?
EC2 có public IPInternet (không cần thêm gì)
Private subnet + NAT GatewayInternet (qua NAT)
Private subnet + KHÔNG có NATVPC Endpoints (bắt buộc)
Yêu cầu security caoVPC Endpoints (recommended)

Tại sao SSM Agent an toàn hơn SSH?

┌──────────────────────────────────────────────────────────────────────────────┐
│              INBOUND (SSH) vs OUTBOUND (SSM) - Bảo mật khác nhau!            │
├──────────────────────────────────────────────────────────────────────────────┤
│                                                                              │
│   ❌ SSH PORT 22 (INBOUND) - Attack surface lớn:                             │
│   ──────────────────────────────────────────────                             │
│                                                                              │
│   Hacker ─────────────────────────────────► EC2 (port 22 OPEN)               │
│          "Brute force password"              ▲                               │
│          "Exploit SSH vulnerability"         │ LẮNG NGHE                     │
│          "Scan port"                          │                              │
│                                                                              │
│   → EC2 mở port, chấp nhận connections từ BẤT KỲ AI                          │
│   → Hacker có thể scan, brute force, exploit                                 │
│                                                                              │
│   ─────────────────────────────────────────────────────────────────────────  │
│                                                                              │
│   ✅ SSM AGENT (OUTBOUND) - Attack surface = 0:                              │
│   ─────────────────────────────────────────────                              │
│                                                                              │
│   Hacker ──────────X──────────► EC2 (NO ports open)                          │
│          "Không thể connect"       │                                         │
│                                   ▼ OUTBOUND                                 │
│                             SSM Service (AWS managed)                        │
│                                                                              │
│   → EC2 KHÔNG mở port nào                                                    │
│   → Hacker KHÔNG THỂ connect đến EC2                                         │
│   → Agent chỉ gọi đến AWS endpoints (trusted)                                │
│                                                                              │
└──────────────────────────────────────────────────────────────────────────────┘
SSH (Port 22 INBOUND)SSM Agent (OUTBOUND)
Ai initiate connection?Ai cũng có thể thửChỉ Agent initiate
Attack surfaceLớn (exposed)0 (không mở port)
Brute force?✅ Có thể❌ Không thể
Port scan?✅ Phát hiện được❌ Không scan được
AuthenticationSSH keys (có thể bị leak)IAM (integrated với AWS)
LoggingPhải setup riêng✅ Tích hợp CloudTrail/CloudWatch

[!TIP] OUTBOUND đến AWS endpoints an toàn hơn nhiều so với INBOUND port mở! Giống như: Nhà đóng kín cửa, bạn chỉ gọi điện ra khi cần - không ai vào được.


Phân loại SSM Tools

┌──────────────────────────────────────────────────────────────────────────────┐
│                         Systems Manager Tools                                │
├──────────────────────────────────────────────────────────────────────────────┤
│                                                                              │
│  🖥️ NODE TOOLS (Quản lý nodes)                                               │
│  ─────────────────────────────────────────────────────────────               │
│  • Run Command       → Chạy commands từ xa trên nhiều nodes                  │
│  • Session Manager   → SSH/RDP không cần mở port, không cần key              │
│  • Patch Manager     → Tự động patch OS và applications                      │
│  • State Manager     → Duy trì cấu hình mong muốn trên nodes                 │
│  • Inventory         → Thu thập thông tin software trên nodes                │
│  • Fleet Manager     → UI dashboard quản lý fleet                            │
│  • Distributor       → Deploy packages đến nodes                             │
│  • Compliance        → Check compliance của patches, configs                 │
│                                                                              │
│  🔄 CHANGE MANAGEMENT (Quản lý thay đổi)                                     │
│  ─────────────────────────────────────────────────────────────               │
│  • Automation        → Tự động hóa tasks (tạo AMI, update, etc.)             │
│  • Maintenance Win.  → Lên lịch chạy tasks định kỳ                           │
│  • Change Calendar   → Định nghĩa khi nào được/không được thay đổi           │
│  • Documents (SSM)   → Define actions (JSON/YAML)                            │
│                                                                              │
│  📦 APPLICATION TOOLS (Quản lý applications)                                 │
│  ─────────────────────────────────────────────────────────────               │
│  • Parameter Store   → Lưu trữ config, secrets (FREE tier available)         │
│  • AppConfig         → Deploy app configurations với rollback                │
│                                                                              │
│  📊 OPERATIONS TOOLS (Operations management)                                 │
│  ─────────────────────────────────────────────────────────────               │
│  • OpsCenter         → Central dashboard cho operational issues              │
│  • Explorer          → Aggregated view của OpsData                           │
│  • Incident Manager  → Quản lý incidents                                     │
│                                                                              │
└──────────────────────────────────────────────────────────────────────────────┘

Node Tools (Chi tiết)

1. Run Command 🚀

Mục đích: Chạy commands từ xa trên nhiều nodes cùng lúc mà không cần SSH.

┌─────────────────────────────────────────────────────────────────────────────┐
│                           Run Command                                       │
├─────────────────────────────────────────────────────────────────────────────┤
│                                                                             │
│  Ví dụ: Cần restart Apache trên 100 servers                                 │
│                                                                             │
│  KHÔNG có Run Command:                                                      │
│  → SSH vào từng server                                                      │
│  → Chạy: sudo systemctl restart httpd                                       │
│  → Repeat 100 lần 😱                                                        │
│                                                                             │
│  VỚI Run Command:                                                           │
│  → Chọn target (tag, instance IDs, all)                                     │
│  → Chọn document: AWS-RunShellScript                                        │
│  → Command: sudo systemctl restart httpd                                    │
│  → Execute → Chạy trên 100 servers cùng lúc ✅                              │
│                                                                             │
└─────────────────────────────────────────────────────────────────────────────┘
FeatureMô tả
Không cần SSHKhông cần mở port 22, không cần SSH keys
Rate ControlChạy theo batches (VD: 10 servers cùng lúc)
Error ThresholdDừng nếu quá nhiều failures
LoggingOutput lưu vào S3 hoặc CloudWatch Logs

2. Session Manager 🔐

Mục đích: Truy cập shell/console vào nodes không cần SSH, không cần mở ports.

┌─────────────────────────────────────────────────────────────────────────────┐
│                         Session Manager                                     │
├─────────────────────────────────────────────────────────────────────────────┤
│                                                                             │
│   TRƯỚC ĐÂY (SSH truyền thống):                                             │
│   ┌─────────────────────────────────────────────────────────────────────┐   │
│   │                                                                     │   │
│   │  User → Internet → Port 22 (phải mở) → EC2 Instance                 │   │
│   │         ↑                   ↑                                       │   │
│   │   SSH Key required    Security risk                                 │   │
│   │                                                                     │   │
│   └─────────────────────────────────────────────────────────────────────┘   │
│                                                                             │
│   VỚI SESSION MANAGER:                                                      │
│   ┌─────────────────────────────────────────────────────────────────────┐   │
│   │                                                                     │   │
│   │  User → AWS Console/CLI → SSM Service → SSM Agent → EC2 Instance    │   │
│   │              ↑                              ↑                       │   │
│   │      IAM Auth (no SSH key)         No inbound ports needed          │   │
│   │                                                                     │   │
│   └─────────────────────────────────────────────────────────────────────┘   │
│                                                                             │
└─────────────────────────────────────────────────────────────────────────────┘
BenefitMô tả
Không cần SSH keysAuthenticate bằng IAM
Không cần bastion hostsDirect access qua SSM
Không cần mở portsKhông mở port 22 (SSH) hoặc 3389 (RDP)
Fully auditableMọi session được log, có thể stream to S3/CloudWatch
Cross-platformLinux shell, Windows PowerShell

[!TIP] Session Manager là cách recommended để access EC2 instances vì security tốt hơn SSH truyền thống.


3. Patch Manager 🔧

Mục đích: Tự động patch OS và applications trên managed nodes.

┌─────────────────────────────────────────────────────────────────────────────┐
│                          Patch Manager                                      │
├─────────────────────────────────────────────────────────────────────────────┤
│                                                                             │
│   ┌─────────────────┐                                                       │
│   │  Patch Baseline │  ← Định nghĩa rules:                                  │
│   │                 │     • Auto-approve patches sau X ngày                 │
│   │                 │     • Approved/Rejected patches list                  │
│   │                 │     • Severity levels                                 │
│   └────────┬────────┘                                                       │
│            │                                                                │
│            ▼                                                                │
│   ┌─────────────────┐                                                       │
│   │  Patch Group    │  ← Nhóm instances (VD: "Production", "Dev")           │
│   └────────┬────────┘                                                       │
│            │                                                                │
│            ▼                                                                │
│   ┌─────────────────┐                                                       │
│   │Maintenance Win. │  ← Lên lịch patching (VD: Chủ nhật 2AM)               │
│   └────────┬────────┘                                                       │
│            │                                                                │
│            ▼                                                                │
│   ┌─────────────────┐                                                       │
│   │ Patch Instances │  ← Scan → Install → Reboot (if needed)                │
│   └─────────────────┘                                                       │
│                                                                             │
└─────────────────────────────────────────────────────────────────────────────┘
FeatureMô tả
Patch BaselinesDefine rules cho việc approve patches
Patch GroupsNhóm instances để apply baselines khác nhau
Scan vs InstallCó thể chỉ scan hoặc scan + install
Compliance ReportsBáo cáo patches nào missing

4. State Manager 📋

Mục đích: Duy trì cấu hình mong muốn trên nodes (desired state).

Ví dụ Use Cases:
  • Bootstrap instances với software khi launch
  • Join Windows instances vào domain
  • Ensure antivirus luôn running
  • Configure SSH settings

5. Inventory 📦

Mục đích: Thu thập metadata về software, configurations trên managed nodes.

Thu thập đượcVí dụ
ApplicationsInstalled software
AWS ComponentsAWS CLI version, SSM Agent version
FilesSpecific files/directories
Network ConfigIP addresses, MAC addresses
Windows UpdatesInstalled updates
Instance DetailsOS version, hostname

Application Tools (Chi tiết)

Parameter Store 🔑 (Quan trọng!)

Mục đích: Lưu trữ configuration datasecrets một cách secure.

┌─────────────────────────────────────────────────────────────────────────────┐
│                          Parameter Store                                    │
├─────────────────────────────────────────────────────────────────────────────┤
│                                                                             │
│   Parameter Types:                                                          │
│   ┌─────────────────────────────────────────────────────────────────────┐   │
│   │                                                                     │   │
│   │  String         → Plain text value                                  │   │
│   │                   VD: /app/config/db_host = "db.example.com"        │   │
│   │                                                                     │   │
│   │  StringList     → Comma-separated values                            │   │
│   │                   VD: /app/config/servers = "srv1,srv2,srv3"        │   │
│   │                                                                     │   │
│   │  SecureString   → Encrypted với KMS                                 │   │
│   │                   VD: /app/secrets/db_password = "***encrypted***"  │   │
│   │                                                                     │   │
│   └─────────────────────────────────────────────────────────────────────┘   │
│                                                                             │
│   Hierarchical Structure:                                                   │
│   ┌─────────────────────────────────────────────────────────────────────┐   │
│   │                                                                     │   │
│   │  /myapp/                                                            │   │
│   │    ├── dev/                                                         │   │
│   │    │   ├── db_host         = "dev-db.example.com"                   │   │
│   │    │   └── db_password     = ***encrypted***                        │   │
│   │    └── prod/                                                        │   │
│   │        ├── db_host         = "prod-db.example.com"                  │   │
│   │        └── db_password     = ***encrypted***                        │   │
│   │                                                                     │   │
│   └─────────────────────────────────────────────────────────────────────┘   │
│                                                                             │
└─────────────────────────────────────────────────────────────────────────────┘

Parameter Store Tiers

FeatureStandard (FREE)Advanced (PAID)
Số parameters10,000100,000
Max size4 KB8 KB
Parameter policies✅ (expiration, notification)
Higher throughput
CostFREE$0.05/parameter/month

So sánh Parameter Store vs Secrets Manager

AspectParameter StoreSecrets Manager
CostFREE (Standard tier)$0.40/secret/month
RotationKhông tự động✅ Automatic rotation
Cross-accountCó (với RAM)
Use caseGeneral configs, simple secretsDatabase credentials, API keys cần rotation

[!TIP]

  • Dùng Parameter Store cho: configs, non-rotating secrets (FREE!)
  • Dùng Secrets Manager cho: DB passwords cần auto-rotation

Change Management Tools

Automation 🤖

Mục đích: Tự động hóa các tasks phức tạp bằng Automation Runbooks.

Ví dụ Use Cases:
  • Tạo Golden AMI tự động
  • Resize EC2 instances
  • Reset Windows password
  • Patch + Reboot + Validate sequence
  • Remediate non-compliant resources

Maintenance Windows ⏰

Mục đích: Lên lịch chạy tasks trong khung thời gian định sẵn.

┌─────────────────────────────────────────────────────────────────────────────┐
│                       Maintenance Window                                    │
├─────────────────────────────────────────────────────────────────────────────┤
│                                                                             │
│   ┌──────────────────────────────────────────────────────────────────────┐  │
│   │  Window: "Weekly-Patching"                                           │  │
│   │  Schedule: Chủ nhật 2AM - 6AM                                        │  │
│   │                                                                      │  │
│   │  Tasks:                                                              │  │
│   │    1. Run Patch Manager scan                                         │  │
│   │    2. Install missing patches                                        │  │
│   │    3. Reboot if needed                                               │  │
│   │    4. Run health check automation                                    │  │
│   │                                                                      │  │
│   │  Targets: Tag = "PatchGroup:Production"                              │  │
│   └──────────────────────────────────────────────────────────────────────┘  │
│                                                                             │
└─────────────────────────────────────────────────────────────────────────────┘

SSM Documents

SSM Documents định nghĩa actions mà Systems Manager thực hiện.

Document TypeDùng bởiMục đích
CommandRun Command, State ManagerChạy commands trên nodes
AutomationAutomationRunbooks cho automated tasks
SessionSession ManagerConfigure session settings
PackageDistributorDefine software packages

Ví dụ Document

# AWS-RunShellScript document
schemaVersion: "2.2"
description: "Run shell script"
parameters:
  commands:
    type: StringList
    description: "Commands to run"
mainSteps:
  - action: "aws:runShellScript"
    name: "runCommands"
    inputs:
      runCommand: "{{ commands }}"

Use Cases phổ biến

1. Secure Access to EC2 (thay thế SSH)

Session Manager:
  ✅ No SSH keys management
  ✅ No bastion hosts
  ✅ No open ports
  ✅ Full audit logging
  ✅ IAM-based access control

2. Centralized Patch Management

Patch Manager + Maintenance Windows:
  → Scan all instances for missing patches
  → Apply security patches automatically
  → Schedule during maintenance windows
  → Generate compliance reports

3. Configuration Management

Parameter Store:
  → Store database connection strings
  → Store API keys (encrypted)
  → Reference from Lambda, ECS, EC2
  → Version control configurations

4. Automation at Scale

Run Command:
  → Install software on 100+ servers
  → Collect logs from all instances
  → Execute scripts without SSHing

Pricing

ComponentPricing
Session ManagerFREE
Run CommandFREE
Patch ManagerFREE
State ManagerFREE
Parameter Store (Standard)FREE (10,000 params)
Parameter Store (Advanced)$0.05/parameter/month
AutomationFREE (first 100k steps/mo), then charges
OpsCenterCharges per OpsItem

[!NOTE] Hầu hết SSM tools là FREE! Đây là điểm mạnh lớn của SSM.


So sánh với các services khác

NeedSSM ToolAlternative
Store secretsParameter StoreSecrets Manager
SSH accessSession ManagerBastion Host + SSH
Run commandsRun CommandSSH scripts
Patch OSPatch ManagerManual patching
ConfigurationState ManagerAnsible, Puppet, Chef
Incident mgmtIncident ManagerPagerDuty, OpsGenie

Tóm tắt

┌─────────────────────────────────────────────────────────────────────────────┐
│                       AWS Systems Manager Summary                           │
├─────────────────────────────────────────────────────────────────────────────┤
│                                                                             │
│  🎯 WHAT:     Centralized management cho EC2, on-prem, multicloud           │
│  💰 COST:     Hầu hết FREE                                                  │
│  🔑 REQUIRES: SSM Agent + IAM Role                                          │
│                                                                             │
│  ┌─────────────────────────────────────────────────────────────────────┐    │
│  │                    Most Important Tools                             │    │
│  │                                                                     │    │
│  │  🚀 Run Command     → Execute commands at scale                     │    │
│  │  🔐 Session Manager → Secure shell without SSH/ports                │    │
│  │  🔧 Patch Manager   → Automated OS patching                         │    │
│  │  🔑 Parameter Store → Store configs/secrets (FREE!)                 │    │
│  │  🤖 Automation      → Runbooks for complex tasks                    │    │
│  │  ⏰ Maint. Windows  → Schedule maintenance tasks                    │    │
│  └─────────────────────────────────────────────────────────────────────┘    │
│                                                                             │
│  ┌─────────────────────────────────────────────────────────────────────┐    │
│  │                       Key Benefits                                  │    │
│  │                                                                     │    │
│  │  ✅ No SSH keys, no bastion hosts, no open ports                    │    │
│  │  ✅ Works with EC2, on-premises, multicloud                         │    │
│  │  ✅ Centralized visibility and control                              │    │
│  │  ✅ Mostly FREE!                                                    │    │
│  │  ✅ Integrates with Organizations                                   │    │
│  └─────────────────────────────────────────────────────────────────────┘    │
│                                                                             │
└─────────────────────────────────────────────────────────────────────────────┘

Tài liệu tham khảo