AWS SSM port forwarding session using AWS-SDK



I am curious whether it is possible to open and maintain SSM port forwarding session using @aws-sdk ssm client. I have seen examples using AWS CLI, but I have not seen examples using SDK.

What I would like is to do something like this:

const { SessionId } = await ssmClient.send(
      new StartSessionCommand({
        Target: 'i-0af865f7bb036b35c', // jump host
        DocumentName: 'AWS-StartPortForwardingSessionToRemoteHost',
        Parameters: {
          host: [''],  // remote db I try connect to
          portNumber: ['5432'],
          localPortNumber: ['5432']

**This should open tunnel from my local port through the jumphost to the database. ** In my case, the session starts, but no local port seems to be open on my localhost. The session then terminates automatically in about 20 seconds.

asked a year ago901 views
1 Answer


In Python, we have to use URL and the token into the Response for sending data to the WebSocket connection. So, my guess is, you have to use the WebSocket protocol to send your data in. To maintain your connection up, you send periodically a probe to keep it alive. Sorry, I don't have any example to show you.

Otherwise, you can create a subprocess/subshell and keep the process ID, to track it.

profile picture
answered a year ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions