Systems Manager: Run Command, Patch Manager, State Manager and Session Manager
Overview
AWS Systems Manager (SSM) is the operations hub for your fleet. With the SSM Agent installed on EC2 instances, on-premises servers and edge devices, you can run commands, install patches, enforce configuration, collect inventory and open shell sessions – without SSH keys, bastion hosts or open inbound ports.
Imagine a facilities team with a master key system: instead of walking to each room with a screwdriver, they send instructions through a central control panel, and every room reports back. SSM is that control panel for servers.
SOA-C03 loves SSM. You need to know the prerequisites for an instance to become a managed node, and which capability solves which task: Run Command (ad hoc), State Manager (continuous desired state), Patch Manager (patching), Session Manager (shell access).
Key Concepts
- Managed node prerequisites: SSM Agent running, an instance profile with
AmazonSSMManagedInstanceCore, and network path to SSM endpoints (internet/NAT or VPC interface endpoints ssm, ssmmessages, ec2messages). - Run Command executes SSM documents on many instances by tags, with rate control (concurrency/error thresholds) and output to S3/CloudWatch.
- Patch Manager uses patch baselines, patch groups (tag Patch Group) and a maintenance window or State Manager association to scan/install patches.
- State Manager associations continuously apply a document (e.g. install agent, join domain) on a schedule to keep desired state.
- Session Manager gives browser/CLI shell access with IAM-controlled, audited and logged sessions (S3/CloudWatch Logs) and no inbound ports.
- Inventory collects software/config metadata; Compliance reports patch and association status.
- Maintenance windows schedule tasks (Run Command, Automation, Lambda) in a defined time period.
- Hybrid Activations register on-premises servers as managed nodes (prefixed mi-).
Detailed Notes
Troubleshooting "instance not showing in Fleet Manager"
| Check | Detail |
|---|---|
| IAM role | Instance profile contains AmazonSSMManagedInstanceCore (or equivalent) |
| Agent | Installed and running (systemctl status amazon-ssm-agent) – preinstalled on Amazon Linux 2/2023, recent Ubuntu, Windows AMIs |
| Network | Outbound 443 to ssm, ssmmessages, ec2messages via NAT, IGW or VPC endpoints; endpoint SG allows 443 from instance |
| DNS | VPC endpoint private DNS enabled; enableDnsSupport true |
| Region | Instance and console in the same Region |
Use Systems Manager Quick Setup to configure role/agent/patching across an organisation.
Run Command
aws ssm send-command --document-name AWS-RunShellScript \
--targets Key=tag:Role,Values=web \
--parameters 'commands=["df -h","systemctl status nginx"]' \
--max-concurrency 25% --max-errors 10% \
--output-s3-bucket-name ops-command-logs --comment "disk check"
aws ssm list-command-invocations --command-id <ID> --details
max-concurrency and max-errors provide rate control so a bad command cannot take down the whole fleet.
Patch Manager
| Concept | Description |
|---|---|
| Patch baseline | Rules for approving patches (classification, severity, auto-approval delay) and exceptions; default baseline per OS |
| Patch group | Tag Patch Group=<name> links instances to a custom baseline |
| Operation | Scan (report only) or Install |
| Reboot option | RebootIfNeeded / NoReboot |
| Compliance | Reported per instance in Patch Manager / Compliance |
aws ssm create-patch-baseline --name prod-linux --operating-system AMAZON_LINUX_2023 \
--approval-rules 'PatchRules=[{PatchFilterGroup={PatchFilters=[{Key=CLASSIFICATION,Values=[Security]},{Key=SEVERITY,Values=[Critical,Important]}]},ApproveAfterDays=3}]'
aws ssm register-patch-baseline-for-patch-group --baseline-id pb-0123 --patch-group prod-web
aws ssm send-command --document-name AWS-RunPatchBaseline \
--targets Key=tag:Patch\ Group,Values=prod-web --parameters Operation=Install,RebootOption=RebootIfNeeded
Schedule installs inside a maintenance window and scans daily using State Manager. Patch Manager also supports patch policies via Quick Setup across organisations.
State Manager association
aws ssm create-association --name AWS-ConfigureAWSPackage \
--targets Key=tag:Env,Values=prod \
--parameters action=Install,name=AmazonCloudWatchAgent \
--schedule-expression "rate(30 days)" --association-name install-cw-agent
Associations re-apply on schedule and on new instance launch, correcting drift in configuration.
Session Manager
aws ssm start-session --target i-0abc123def456
aws ssm start-session --target i-0abc123def456 --document-name AWS-StartPortForwardingSession \
--parameters portNumber=3306,localPortNumber=13306
Benefits: no SSH keys, no bastion, no inbound security group rules, IAM-based authorisation (restrict by tags), and session logs to S3/CloudWatch with optional KMS encryption. The Session Manager plugin is required for the CLI.
Which tool when?
| Need | Tool |
|---|---|
| One-off command on many instances | Run Command |
| Keep config enforced continuously | State Manager |
| Patch OS on schedule | Patch Manager + Maintenance Windows |
| Interactive shell without SSH | Session Manager |
| Multi-step workflow / approvals | Automation |
| Software inventory | Inventory |
An instance appears under Fleet Manager only when all of these hold: the SSM Agent is running, the instance profile grants AmazonSSMManagedInstanceCore, and it reaches the Systems Manager endpoints (internet/NAT or the ssm, ssmmessages and ec2messages interface endpoints).
| Symptom | Cause | Fix |
|---|---|---|
| Instance not listed | No instance profile, agent stopped, no route to endpoints | Attach role, start agent, add VPC endpoints |
| Run Command stays Pending | Agent offline or target tag mismatch | Check PingStatus in describe-instance-information |
| Session Manager denied | IAM user lacks ssm:StartSession or document restrictions | Grant permission, check session preferences |
| Patch compliance missing | No patch baseline match or no association scan | Run AWS-RunPatchBaseline with Scan |
| On-premises server needed | Not EC2 | Create a hybrid activation; servers register as mi- managed nodes |
aws ssm describe-instance-information --query "InstanceInformationList[].[InstanceId,PingStatus,AgentVersion]"
aws ssm send-command --document-name AWS-RunShellScript --targets Key=tag:Env,Values=prod \
--parameters commands="systemctl status nginx" --max-concurrency 10% --max-errors 1
aws ssm start-session --target i-0abc123
aws ssm put-parameter --name /app/prod/db-url --type SecureString --value "host=db" --overwrite
Session Manager can send session logs to S3 and CloudWatch Logs and use KMS encryption; CloudTrail records StartSession. Parameter Store holds config and secrets (Standard vs Advanced tiers) while Secrets Manager adds rotation. Use --max-concurrency and --max-errors for safe rollouts.
Real World Example
Scenario – eliminate bastion hosts and patch 400 servers. A company's auditors object to open SSH ports and manual patching. The ops team attaches AmazonSSMManagedInstanceCore through an instance profile, adds SSM VPC endpoints for private subnets, and removes port 22 from all security groups.
Engineers now use Session Manager with IAM-based access and logs in S3. Patch Manager with a baseline (critical/security after 3 days) scans nightly, and installs during a Sunday maintenance window, staggered by patch group with 10% concurrency. A compliance dashboard shows patch status to auditors.
Architecture Diagram
- 1An operator authenticates with IAM and starts a session or command.
- 2Systems Manager queues the request for the SSM Agent.
- 3The agent polls through outbound HTTPS (NAT or VPC endpoints) and executes it.
- 4Output and session logs are delivered to S3 or CloudWatch Logs for audit.
Best Practices
- ✓Use Session Manager instead of SSH/bastions; close inbound port 22/3389.
- ✓Create VPC interface endpoints (ssm, ssmmessages, ec2messages) for private subnets.
- ✓Use tags and patch groups to stage rollouts; set rate control on Run Command.
- ✓Run Scan daily and Install in maintenance windows; monitor compliance.
- ✓Log sessions and commands to S3/CloudWatch Logs with encryption.
Common Interview Questions
Exam Tips
SOA-C03 focus
- Remote shell without opening ports or key pairs -> Session Manager.
- Instance missing in Systems Manager -> instance profile, agent, VPC endpoints/NAT.
- Patch on schedule with approval rules -> Patch Manager + baselines + maintenance window.
- Enforce config repeatedly -> State Manager association; tag targets rather than IDs.
Finished this lesson?
0 of 46 lessons done · 0% of the course

