How can I resume session with the aws cli?

2.6k views Asked by At

I've started a session with the command aws ssm start-session --target <instance id> --region <my region>, and when I do that I get Starting session with SessionId <sessionid> and am logged into the ec2 instance. I then left my computer and the connection timed out. Now I want to return to that session.

I tried the command aws ssm resume-session --session-id <sessionid from above> --region <my region> which returns something like { "SessionId": "<sessionid from above>", "TokenValue": "", "StreamUrl": "<url here>" } . But how do I actually connect again? That leaves me on my local computer, whereas the start session command puts me on the aws instance. If I try the start-session command again, I get a brand new session. I feel like I am missing something obvious!

2

There are 2 answers

0
Bruno Schaatsbergen On

as the aws cli docs state you'll need to be sure that you've configured the following:

Note that this interactive command requires the Session Manager plugin to be installed on the client machine making the call.

For more information, see Install the Session Manager Plugin for the AWS CLI in the AWS Systems Manager User Guide: https://docs.aws.amazon.com/systems-manager/latest/userguide/session-manager-working-with-install-plugin.html

Also please be aware of the following:

ResumeSession, Reconnects a session to an instance after it has been disconnected. Connections can be resumed for disconnected sessions, but not terminated sessions. This command is primarily for use by client machines to automatically reconnect during intermittent network issues. It is not intended for any other use

You can use the AWS Systems Manager console or the AWS Command Line Interface (AWS CLI) to end a session that you started to connect to an instance in your account. If there is no user activity after 20 minutes, a session is ended. After a session is ended, it can't be resumed.

anyhoo, I've you started a session and timeout/disconnect the resume session command will provide you with a new instance that you can immediately use as per the docs:

This resume-session example resumes a Session Manager session with an instance after it has been disconnected.

0
zauwn On

I believe it is not possible to resume a session:

https://awscli.amazonaws.com/v2/documentation/api/latest/reference/ssm/resume-session.html

This command is primarily for use by client machines to automatically reconnect during intermittent network issues. It isn’t intended for any other use.