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
已提問 1 年前檢視次數 844 次
1 個回答
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
已回答 1 年前

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南