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
preguntada hace un año846 visualizaciones
1 Respuesta
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
respondido hace un año

No has iniciado sesión. Iniciar sesión para publicar una respuesta.

Una buena respuesta responde claramente a la pregunta, proporciona comentarios constructivos y fomenta el crecimiento profesional en la persona que hace la pregunta.

Pautas para responder preguntas