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

AWS Cloud

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.

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?

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?

Start with a Linux instance that has no incoming SSH rule. The Systems Manager Agent runs on the node and establishes the connections that the service uses to manage it. The node needs permission to register and communicate. A person opening a session needs their own permission to start one. A console entry showing the node is online means the systems can communicate; it is a separate check from whether your user can log in. Draw node, agent, service and operator before testing the session.

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
Manage an instance through Systems ManagerManaged instance: Agent, role and connectivity are ready; Systems Manager service: Checks the operator’s permission for the action; Session or command: Runs on the selected managed node; Result and audit: Inspect output and configured logsManaged instanceAgent, role and connectivity arereadySystems Manager serviceChecks the operator’s permission forthe actionSession or commandRuns on the selected managed nodeResult and auditInspect output and configured logs
Audited ops actions

4. How to enable a safe managed node

Choose the tool by the outcome. Session Manager is for an interactive terminal. Run Command asks the managed node to execute a document and report a result. Patch Manager helps apply a planned patch policy, usually in a controlled window. On the same lab host, compare a terminal check such as whoami with a short Run Command output. Record the node ID and current status so you can tell whether a problem is about the wrong target, the agent connection or the command itself.

  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

Expect the disposable instance to appear online before opening a session. Read its identity in the terminal and compare with the intended lab instance. In Run Command, find the returned output and status for that same node. If it never appears, check agent service, Region, permissions and network connectivity to required service endpoints. End the session and remove the disposable resources afterward.

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

  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.

Practise this chapter

Interview questions and answers

An EC2 instance is online in Systems Manager, but your user cannot start a session. What does “online” prove?

It shows the node registered and communicated with the service. The operator still needs permission to start the selected session. Check the user’s grant, target and Region. Test with an approved lab identity rather than exposing an inbound SSH rule to fix the denial.

Check your understanding

Choose an answer, then compare your reasoning with the explanation.

0 of 3 answered correctly
1. Which component runs on the managed Linux node and communicates with Systems Manager?

Answer and explanation

B. SSM Agent

The agent establishes service connectivity using the node’s authorization and network path.

2. Which tool is suited to a repeatable document execution on selected nodes?

Answer and explanation

A. Run Command

Run Command sends a configured command document and reports execution results. Session Manager supports interactive work.

3. No managed node appears online. What should you check first?

Answer and explanation

B. Agent service, node role, Region and outbound path to its service endpoints

Registration and periodic communication need the agent, permissions and network path.

Practice Tasks

Practice checks run in your browser. They check the answer for this exercise; they do not create resources or connect to your AWS account.

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

See managed nodes.

Describe instance information.

  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

Agent online?

Get connection status for i-0123456789abcdef0.

  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

Automation docs.

List SSM documents.

  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 Apply the lesson: scenario 4

Which Systems Manager feature can provide an interactive session without opening inbound SSH port 22?

  1. Read the situation and identify what you need to decide.
  2. Work through the relevant concept or calculation.
  3. Enter only the requested term or number.
  4. Check your answer, then read the explanation.

Easy Apply the lesson: scenario 5

The instance has the correct IAM role but is not an online managed node. Which software agent should you inspect first?

  1. Read the situation and identify what you need to decide.
  2. Work through the relevant concept or calculation.
  3. Enter only the requested term or number.
  4. Check your answer, then read the explanation.

Medium Get parameter

Config values.

Get parameter /londonlegal/db-host with decryption.

  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

Recent Run Command.

List commands.

  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

Patch policy.

Describe patch baselines.

  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

Collected facts.

List inventory entries for i-0123456789abcdef0.

  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

App config LP.

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

  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

Prefer SSM over SSH22.

JSON prefer_session_manager true.

  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 Apply the lesson: scenario 12

An application credential needs managed secret storage and a rotation workflow. Which AWS service taught here is a suitable starting point?

  1. Read the situation and identify what you need to decide.
  2. Work through the relevant concept or calculation.
  3. Enter only the requested term or number.
  4. Check your answer, then read the explanation.

Medium Bastion open 22 bad — 0

Prefer SSM.

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

  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

Fleet shell.

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

  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

Session LP.

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

  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

Maintenance.

JSON window cron sun-02:00.

  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.