Ravindra BagaleCourses & study guides मराठी Track your progress

AWS Systems Manager: Session Manager, Patch and Run Command Explained

Opening port 22 to the world so you can SSH is an old habit — and a gift to scanners. AWS Systems Manager (SSM) lets you start a shell with Session Manager, run commands on fleets, patch on a schedule, and store parameters — without bastion sprawl.

What you'll learn in this chapter

  • Why SSM beats open SSH bastions
  • What Session Manager, Run Command, Patch, Parameter Store are
  • How to enable managed instances safely
  • Industries using SSM for ops
  • Lab, errors, FAQ, interview

1. Everyday example first

An Indore team manages 40 Amazon Linux boxes. Instead of sharing one PEM file on WhatsApp, instances use an IAM role with AmazonSSMManagedInstanceCore. Ops start Session Manager from the console, run a script with Run Command, and patch on Sundays via Patch Manager.

2. Why Systems Manager?

Why do we need this?

Bastions need patching, keys, and network paths. SSM Agent + IAM gives auditable sessions, API-driven commands, and patch compliance — better for fleets and auditors.

  • No inbound 22 required when using Session Manager
  • Fleet-wide scripts with Run Command
  • Patch baselines and compliance reports
  • Parameter Store for config (Secrets Manager for secrets)

3. What is in SSM?

What is it?

Systems Manager is a suite. Session Manager opens an interactive shell or port forward through the SSM API. Run Command executes documents. Patch Manager applies baselines. Parameter Store holds hierarchical config. Inventory and State Manager add desired-state tooling.

CapabilityPlain job
Session ManagerShell/port-forward without SSH keys
Run CommandRun a document on many instances
Patch ManagerDefine baselines and maintenance windows
Parameter StoreConfig strings/paths; advanced tier available
InventoryCollect OS/app metadata
IAM role + SSM Agent → Session / Run / PatchEC2 without open SSH
Audited ops actions

4. How to enable a safe managed node

How to do it (step by step)

  1. Attach AmazonSSMManagedInstanceCore (or tighter clone) to the instance role.
  2. Ensure agent installed/running (AL2023 usually has it).
  3. VPC endpoints for SSM if private subnets without NAT (com.amazonaws.region.ssm etc.).
  4. Start Session Manager; confirm CloudTrail/Session logs to S3/CW if required.
  5. Create a Run Command doc or use AWS-RunShellScript for a controlled script.
  6. Define a patch baseline and maintenance window off-peak.
  7. Store non-secret config in Parameter Store (/app/dev/db_host).
  8. Use Secrets Manager for DB passwords; reference from apps.
  9. Least privilege: separate who can StartSession vs SendCommand.
  10. Remove public :22 from security groups when Session Manager works.
# Mental model
# SSM agent → managed instance
# Session Manager (no SSH inbound)
# Patch Manager baselines + Run Command docs

5. Parameter Store vs Secrets Manager

StoreUse for
Parameter StoreConfig, feature flags, license paths
Secrets ManagerRotating secrets, RDS integration
SSM Advanced tierLarger params / higher throughput

6. Multi-industry notes

Factories use Run Command to push agent configs to shop-floor gateways. Banks log every Session Manager start to a central bucket for audit. Startups kill bastion costs by going Session Manager-only in private subnets.

7. Industries and roles

  • IT ops: fleet patching weekends
  • DevOps: pipeline Run Command smoke tests
  • Security: remove SSH keys from laptops
  • SaaS: parameterized configs per env
  • Healthcare: audited access to clinical jump boxes

8. Lab: Session Manager on a tiny EC2

Do this in ap-south-1 (Mumbai) unless your org forbids it. Set a budget alert first.

How to do it (step by step)

  1. Launch Amazon Linux 2023 with SSM-capable role; no public SSH rule.
  2. Confirm Managed Instances shows Online.
  3. Start Session Manager; run whoami and hostnamectl.
  4. SendCommand uname -a; view output in console.
  5. Create parameter /lab/hello = world; read with get-parameter.

Cleanup (stop billing)

  1. Terminate instance; delete parameter; remove lab role if unused.
  2. Delete VPC endpoints if you created only for lab.

9. Common errors and fixes

Each row is a real mistake students and juniors hit. Read the fix before you panic.

Error / symptomFix
Agent Offline foreverCheck role, DNS, endpoints/NAT, agent service.
Opened 22 “just in case”Close when SSM works; reduce attack surface.
Shared PEM still in SlackRotate; prefer SSM only.
Everyone allowed SendCommandSeparate break-glass role.
Secrets in Parameter Store Standard as plaintext habitUse SecureString + KMS or Secrets Manager.
Patch without maintenance windowAvoid random reboots at noon.
No session loggingEnable to S3/CloudWatch for audit.
Wrong region in CLITarget instance region.
SSM on Windows without agent configInstall/configure official agent.
Bastion + SSM both unmanagedPick one path; document.

10. Troubleshooting checklist

  1. TargetNotConnected: agent/IAM/network path.
  2. AccessDenied StartSession: missing ssm:StartSession + tunnel perms.
  3. Run Command pending: instance busy or agent stuck — restart agent.
  4. Patch status NonCompliant: review baseline exclusions.
  5. Parameter NotFound: path typo or wrong account.
  6. Private subnet: add interface endpoints for ssm, ssmmessages, ec2messages.

11. FAQ

Q. Is Session Manager free?

No SSM charge for many features; data transfer/logs may cost — check pricing.

Q. Replace bastion fully?

Often yes for EC2; edge cases remain.

Q. Hybrid servers?

SSM hybrid activation for on-prem.

Q. Ansible vs Run Command?

Both ok; Run Command is AWS-native quick fleet ops.

Q. Parameter Store free tier?

Standard parameters have free tier limits.

Q. Port forward?

Session Manager supports port forwarding use cases.

12. Interview Q&A

Q. What is Session Manager?

SSM feature for shell/port-forward without inbound SSH.

Q. Managed instance prerequisites?

Agent + IAM role + network to SSM endpoints.

Q. Run Command vs SSH script?

API-audited fleet execution with documents.

Q. Patch Manager?

Baselines + windows to drive OS patch compliance.

Q. SecureString?

KMS-encrypted parameter value.

Q. Why remove port 22?

Shrink attack surface; rely on IAM + SSM.

13. Tips in English, Marathi and Hindi

Ravindra Bagale's Tip (EN)

If Session Manager works, delete the “temporary” SSH rule the same day. Temporary rules become permanent holes.

Ravindra Bagale's Tip (MR)

Session Manager चाललं की त्याच दिवशी temporary SSH rule काढा.

Tip (HI)

Session Manager चलते ही उसी दिन temporary SSH rule हटाओ — अस्थायी छेद स्थायी हो जाते हैं।

Try at home

  1. List the three VPC interface endpoints often needed for private SSM.
  2. Write an IAM bullet: who may StartSession on prod tags only.
  3. Compare Parameter Store vs Secrets Manager in 3 lines.

In short

  1. SSM manages instances without open SSH.
  2. Session Manager + Run Command + Patch cover daily ops.
  3. Parameters for config; Secrets Manager for secrets.
  4. Log sessions and least-privilege the verbs.

Revision, interview and comparison cards

Revise this lesson in a few minutes. Save the cards on your phone or download them as PNG files. The QR code on each card opens this lesson.

Revision card: Systems Manager in one line. Opening SSH 22 to every server is risky and hard to audit. Systems Manager manages EC2/hybrid nodes: Session Manager, Run Command, Patch, Parameter Store. Install/agent healthy → IAM instance profile → use Session Manager; patch with baselines. Ops shells into prod via Session Manager with CloudTrail; no bastion port 22.
Revision card: Systems Manager in one line · Download PNG · Open card page
Revision card: Session Manager vs SSH. Bastions and long-lived keys still get forgotten and scanned. Session Manager uses IAM + SSM agent over the AWS API — no inbound 22 required. Prefer Session Manager; log sessions to S3/CloudWatch; break-glass only if needed. Auditor asks who ran commands last night — Session logs answer.
Revision card: Session Manager vs SSH · Download PNG · Open card page
Comparison: Session Manager vs SSH to bastion. Session Manager: No inbound 22; IAM + agent; session logs. SSH to bastion: Open SSH path; keys/bastion lifecycle risk.
Comparison: Session Manager vs SSH to bastion · Download PNG · Open card page
Comparison: SSM Parameter Store vs Secrets Manager. SSM Parameter Store: Hierarchical parameters; SecureString optional. Secrets Manager: Secret lifecycle with managed rotation.
Comparison: SSM Parameter Store vs Secrets Manager · Download PNG · Open card page
Interview card: Name three SSM capabilities. Session Manager, Run Command/Patch Manager, Parameter Store (among others). Needs healthy agent + instance profile. Patch Tuesday baseline + Session for break-glass.
Interview card: Name three SSM capabilities · Download PNG · Open card page
Interview card: Why avoid open SSH 22?. Inbound 22 is scanned and keys/bastions drift; Session Manager uses IAM without that port. Log sessions for audit. SG has no 22; ops uses StartSession.
Interview card: Why avoid open SSH 22? · Download PNG · Open card page
Interview card: Parameter Store vs Secrets Manager?. SSM great for config (SecureString OK); Secrets Manager for rotating credentials lifecycle. Do not store the same DB password in both. DB URL in SSM; DB password rotating in Secrets Manager.
Interview card: Parameter Store vs Secrets Manager? · Download PNG · Open card page
Interview card: How does Patch Manager help?. Baselines + windows scan/install patches across fleets with reporting. Start nonprod; measure reboot impact. AmazonLinux baseline every Sunday 02:00 window.
Interview card: How does Patch Manager help? · Download PNG · Open card page

More cards: Ravi Sir's Cards.

Practice Tasks

About this scenario

London Legal LLP is a law business in London. Oliver Hughes looks after its IT and cloud work. They count money in GBP and run their AWS resources in the eu-west-2 Region. In the tasks below you do real jobs for them using what this lesson teaches. All names, account IDs, IP addresses and numbers are made up for practice.

0 / 16

Easy Describe instance information

Why: See managed nodes.

What to do: Describe instance information.

How:
  1. Read the task and decide which AWS service it is about.
  2. Write aws, then the service name, then the operation (the action word).
  3. Add each needed flag (--name) followed by its value from the task.
  4. Flags can be in any order. Click Check answer.

Easy Get connection status

Why: Agent online?

What to do: Get connection status for i-0123456789abcdef0.

How:
  1. Read the task and decide which AWS service it is about.
  2. Write aws, then the service name, then the operation (the action word).
  3. Add each needed flag (--name) followed by its value from the task.
  4. Flags can be in any order. Click Check answer.

Easy List documents

Why: Automation docs.

What to do: List SSM documents.

How:
  1. Read the task and decide which AWS service it is about.
  2. Write aws, then the service name, then the operation (the action word).
  3. Add each needed flag (--name) followed by its value from the task.
  4. Flags can be in any order. Click Check answer.

Easy Open 22 not required — 1

Why: SSM benefit.

What to do: Enter 1 if Session Manager can avoid inbound SSH.

How:
  1. Write down the numbers the task gives you.
  2. Work it out step by step on paper.
  3. Type only the final answer in the box.
  4. Click Check answer.

Easy Agent required — 1

Why: Managed node.

What to do: Enter 1 if SSM agent must be healthy.

How:
  1. Write down the numbers the task gives you.
  2. Work it out step by step on paper.
  3. Type only the final answer in the box.
  4. Click Check answer.

Medium Get parameter

Why: Config values.

What to do: Get parameter /londonlegal/db-host with decryption.

How:
  1. Read the task and decide which AWS service it is about.
  2. Write aws, then the service name, then the operation (the action word).
  3. Add each needed flag (--name) followed by its value from the task.
  4. Flags can be in any order. Click Check answer.

Medium List commands

Why: Recent Run Command.

What to do: List commands.

How:
  1. Read the task and decide which AWS service it is about.
  2. Write aws, then the service name, then the operation (the action word).
  3. Add each needed flag (--name) followed by its value from the task.
  4. Flags can be in any order. Click Check answer.

Medium Describe patch baselines

Why: Patch policy.

What to do: Describe patch baselines.

How:
  1. Read the task and decide which AWS service it is about.
  2. Write aws, then the service name, then the operation (the action word).
  3. Add each needed flag (--name) followed by its value from the task.
  4. Flags can be in any order. Click Check answer.

Medium List inventory entries

Why: Collected facts.

What to do: List inventory entries for i-0123456789abcdef0.

How:
  1. Read the task and decide which AWS service it is about.
  2. Write aws, then the service name, then the operation (the action word).
  3. Add each needed flag (--name) followed by its value from the task.
  4. Flags can be in any order. Click Check answer.

Medium Allow GetParameter one

Why: App config LP.

What to do: Allow ssm:GetParameter on arn:aws:ssm:eu-west-2:114543297314:parameter/londonlegal/db-host.

How:
  1. Start with { "Version": "2012-10-17", "Statement": [ ... ] }.
  2. In each statement write Effect, Action and Resource.
  3. Give only what the task needs (least privilege).
  4. Use double quotes and commas correctly. Click Check answer.

Medium Session preference JSON

Why: Prefer SSM over SSH22.

What to do: JSON prefer_session_manager true.

How:
  1. Start from the top-level keys the task names.
  2. Indent child keys with 2 spaces (no tabs).
  3. Fill in each property with the value from the task.
  4. Click Check answer. Key order does not matter.

Medium Secrets Manager still for app secrets — 1

Why: Choose store.

What to do: Enter 1 if Secrets Manager often fits rotating app secrets.

How:
  1. Write down the numbers the task gives you.
  2. Work it out step by step on paper.
  3. Type only the final answer in the box.
  4. Click Check answer.

Medium Bastion open 22 bad — 0

Why: Prefer SSM.

What to do: Is permanent open SSH 22 to bastion best practice? Enter 0 for no.

How:
  1. Write down the numbers the task gives you.
  2. Work it out step by step on paper.
  3. Type only the final answer in the box.
  4. Click Check answer.

Hard Send AWS-RunShellScript

Why: Fleet shell.

What to do: Send command AWS-RunShellScript to i-0123456789abcdef0 with comment lab.

How:
  1. Read the task and decide which AWS service it is about.
  2. Write aws, then the service name, then the operation (the action word).
  3. Add each needed flag (--name) followed by its value from the task.
  4. Flags can be in any order. Click Check answer.

Hard Allow StartSession

Why: Session LP.

What to do: Allow ssm:StartSession on arn:aws:ec2:eu-west-2:114543297314:instance/i-0123456789abcdef0.

How:
  1. Start with { "Version": "2012-10-17", "Statement": [ ... ] }.
  2. In each statement write Effect, Action and Resource.
  3. Give only what the task needs (least privilege).
  4. Use double quotes and commas correctly. Click Check answer.

Hard Patch window JSON

Why: Maintenance.

What to do: JSON window cron sun-02:00.

How:
  1. Start from the top-level keys the task names.
  2. Indent child keys with 2 spaces (no tabs).
  3. Fill in each property with the value from the task.
  4. Click Check answer. Key order does not matter.