Sub topic 3
Starting Session Manager Sessions
Assume you understand EC2 instances, IAM policies, and basic AWS CLI use. The instance must have SSM Agent, an instance profile with AmazonSSMManagedInstanceCore, and network access to Systems Manager endpoints.
Start a Session
In the AWS console, open Systems Manager, choose Session Manager, and select Start session. Choose an online managed instance, then choose Start session.
The CLI uses your IAM identity and the Session Manager plugin:
aws ssm start-session --target i-0123456789abcdef0Session Manager opens an interactive shell without requiring an inbound security group rule or a public IP address.
Use SSH Through Session Manager
You can keep using SSH while replacing the network path with a Session Manager tunnel. Add this to ~/.ssh/config:
Host i-* mi-*
ProxyCommand sh -c "aws ssm start-session --target %h --document-name AWS-StartSSHSession --parameters 'portNumber=%p'"Then connect with your normal key and AMI-specific user:
ssh -i ~/.ssh/my-key.pem ec2-user@i-0123456789abcdef0The instance still needs an SSH server and a valid key. Session Manager removes the need for inbound port 22, but it does not replace SSH authentication.
Forward a Remote Port
Port forwarding exposes a service on the instance through a local port:
aws ssm start-session \
--target i-0123456789abcdef0 \
--document-name AWS-StartPortForwardingSession \
--parameters '{"portNumber":["80"],"localPortNumber":["8080"]}'While the session runs, http://localhost:8080 reaches port 80 on the instance.
Log and Audit Sessions
Configure Session Manager preferences to send session output to CloudWatch Logs, Amazon S3, or both. The instance role needs permission to write the selected logs. CloudTrail records API actions such as StartSession and TerminateSession; it does not replace shell-content logging.
Choose an Access Method
| Requirement | Suitable method |
|---|---|
| Traditional administration with an SSH key | SSH |
| Temporary public-key access | EC2 Instance Connect |
| No inbound ports and centralized IAM control | Session Manager |
Exercise
Which method should you choose when port 22 must remain closed and shell activity must be centrally auditable?
Show answer
Use Session Manager, with session logging configured and IAM permissions limited to the required instances.