AWS SSM port forwarding session using AWS-SDK

0

Hello,

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: ['bastion-tst2-myslsdb.cluster-xxxxxxxxx.eu-west-1.rds.amazonaws.com'],  // 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.

simon
asked a year ago804 views
1 Answer
1

Hi,

In Python, we have to use URL and the token into the Response for sending data to the WebSocket connection. https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/ssm/client/start_session.html 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
Donov
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