Running Commands and Opening Sessions with Systems Manager
This lesson explains how Run Command executes documents on many nodes at once and how Session Manager gives an interactive shell without SSH keys or open ports.
Learning outcomes
After completing this lesson, you will be able to:
- Run commands at scale with rate controls.
- Open logged sessions with Session Manager.
- Remove SSH access from a fleet.
Run Command
Run Command executes an SSM document of type Command, such as AWS-RunShellScript, AWS-RunPowerShellScript, AWS-ConfigureAWSPackage or AWS-InstallApplication, on chosen managed nodes. Targets can be instance IDs, tags or resource groups. Rate control sets concurrency (how many nodes at once, as a number or percentage) and an error threshold (how many failures stop the command). Output can be written to S3 and CloudWatch Logs, because the console shows only the first 2,500 characters. Commands are logged in CloudTrail, and notifications can be sent to SNS. No SSH access or open inbound ports are required.
aws ssm send-command --document-name AWS-RunShellScript \
--targets Key=tag:Role,Values=web \
--parameters 'commands=["sudo systemctl restart nginx"]' \
--max-concurrency 10% --max-errors 1 \
--cloud-watch-output-config CloudWatchOutputEnabled=true,CloudWatchLogGroupName=/ssm/runcommand2,500characters
Command output shown in the console
Running commands safely
Session Manager
Session Manager opens a browser or CLI shell session to a managed node through the SSM Agent. Inbound ports such as 22 and 3389, bastion hosts and SSH keys are not needed, and access is controlled with IAM policies such as ssm:StartSession scoped by instance tags. Session preferences can encrypt sessions with a KMS key, run sessions as a specific operating system user, set idle timeouts and log session activity to S3 and CloudWatch Logs; session start and end are recorded in CloudTrail. Port forwarding sessions tunnel a local port to a port on the instance or to a remote host such as an RDS database, and SSH and SCP can also be tunnelled through Session Manager.
The following table compares the ways to reach a shell on an instance.
| Method | Inbound port | Credentials | Auditing |
|---|---|---|---|
| Session Manager | None | IAM | Session logs to S3/CloudWatch, CloudTrail |
| EC2 Instance Connect | 22 (or Instance Connect Endpoint for private subnets) | IAM pushes a 60-second key | CloudTrail |
| SSH with key pairs | 22 | Long-lived private key | OS logs only |
| Bastion host | 22 on the bastion | Keys on bastion and targets | OS logs only |
The following diagram shows a session to a private instance and a port-forwarding session to RDS.

Session Manager
Removing SSH access
A security audit requires that no security group allows port 22 and that all shell activity is recorded. The team confirms all instances are managed nodes, configures Session Manager preferences to send session logs to an encrypted CloudWatch log group and S3 bucket and to require KMS encryption, and grants engineers an IAM policy that allows ssm:StartSession only on instances tagged with their team. The inbound SSH rules are then removed. Engineers who need to reach a private database use a port forwarding session with the AWS-StartPortForwardingSessionToRemoteHost document.
Which Run Command settings limit how many nodes run a command at once and when it stops?
Show answer
Concurrency and error threshold rate control.
Exam Tips
Remember for the exam
- Run Command targets nodes by tag with concurrency and error threshold rate control.
- Send Run Command output to S3 or CloudWatch Logs for full output.
- Session Manager needs no inbound ports or SSH keys; access is controlled by IAM.
- Log session activity to S3 and CloudWatch Logs through session preferences.
- Port forwarding sessions reach private databases without a bastion.