Sub topic 11
Starting a session from the console and the AWS CLI
This chapter assumes you have read the earlier chapters on Session Manager prerequisites and IAM permissions. Your instance should already run SSM Agent with an instance profile, and your IAM identity should be allowed to call ssm:StartSession. You also need the AWS CLI configured with credentials.
Check that the instance is ready
Before you start a session, confirm that the instance has registered with Systems Manager. An instance that has not registered will not appear as a target.
aws ssm describe-instance-information \
--query "InstanceInformationList[].[InstanceId,PingStatus]" \
--output textEach line shows an instance ID and its ping status. Online means the agent is reachable and you can start a session. If your instance is missing, or shows ConnectionLost, the cause is usually one of these:
- The instance profile lacks the permissions the agent needs.
- The instance has no network path to the Systems Manager endpoints.
- SSM Agent is not running.
Start a session from the console
The console needs no local tools.
- Open the EC2 console and select the instance.
- Choose Connect.
- Open the Session Manager tab.
- Choose Connect.
A browser-based terminal opens. The Connect button is disabled if the instance is not registered or if your IAM identity lacks permission. The shell starts as ssm-user, not ec2-user. Run whoami to confirm.
Start a session with the AWS CLI
The CLI needs the Session Manager plugin, which is installed separately from the AWS CLI. Without it, the command fails with an error saying the plugin was not found.
aws ssm start-session --target i-0123456789abcdef0This opens an interactive shell using your IAM credentials. No key pair is used and no inbound port is open. Type exit to end the session.
The agent keeps an outbound connection to Systems Manager open. When you start a session, the service relays your input through that existing connection. This is why the instance needs no inbound rule.
Choose a profile and region
The target must be in the region you are calling. Pass --region or --profile when your defaults do not match the instance.
aws ssm start-session \
--target i-0123456789abcdef0 \
--region us-east-1 \
--profile opsCommon errors
| Symptom | Likely cause |
|---|---|
| `TargetNotConnected` | The agent is offline or the instance has no route to the endpoints |
| `AccessDeniedException` | Your IAM policy does not allow `ssm:StartSession` on that instance ARN |
| `SessionManagerPlugin is not found` | The plugin is not installed locally |
| Instance missing from the console list | Wrong region, or the instance never registered |
List and end sessions
You can see your active sessions and end one from another terminal.
aws ssm describe-sessions --state Active
aws ssm terminate-session --session-id your-user-0123456789abcdef0The policy shown in the IAM chapter limits TerminateSession to sessions whose ID starts with your user name. Trying to end someone else's session returns an access error.
Exercise
You run aws ssm start-session --target i-0123456789abcdef0 and get TargetNotConnected. The instance is running and your IAM policy allows ssm:StartSession. Which command do you run first, and what result confirms the problem?
Show answer
Run aws ssm describe-instance-information and look for the instance. If it is absent or its PingStatus is ConnectionLost, the agent is not reaching Systems Manager. Check the instance profile, the network path to the endpoints, and whether SSM Agent is running.