Skip to content

SSM create the session, but also handle the port forwarding. #5935

Open
@LoganWlv

Description

@LoganWlv

Describe the feature

Provide a class to handle the port forwarding after creating a SSM session using AWS-StartPortForwardingSessionToRemoteHost.

Use Case

My use case is the same as described here.
Need to create a session targeting a bastion instance ID to access a database within an RDS cluster.

I'm writing a tool with Java to ease debugging throughout the team. It is easier to write with Java and also easier to maintain and evolve than a shell script that would make use of the AWS CLI:

aws ssm start-session

Today, my solution is mostly written in Java except the session starting part:

ssmProcess = new ProcessBuilder()
                    .command(                          "aws", "ssm", "start-session",
                            "--target", instanceId,
                            "--document-name", "AWS-StartPortForwardingSessionToRemoteHost",
                            "--parameters", String.format(
                                    "host=\"%s\",portNumber=\"%s\",localPortNumber=\"%s\"",
                                    rdsAddress, rdsPort, LOCAL_PORT
                            ),
                            "--profile", env
                    )
                    .start();

It is hard to find documentation on how the WebSocket should be implemented and what kind of message should be sent, so I quickly gave up (+ my network skills are weak 😅 ).

=> jdbc:postgresql://localhost:5433/myDb
=> how do I send the request to the websocket opened connection? How AWS expects the token to be passed in the handshake.
=> ws://ssm-region...
=> Receive message, AWS handles the redirection to RDS

Proposed Solution

StartSessionRequest request = StartSessionRequest.builder()
                    .target(instanceId)
                    .documentName("AWS-StartPortForwardingSessionToRemoteHost")
                    .parameters(parameters)
                    .build();

I don't think the above should start the port forwarding, but it would be nice to provide a class that with the streamURL, token and localPort (+ whatever needed) does the port forwarding, and handle all AWS specificities.

Other Information

No response

Acknowledgements

  • I may be able to implement this feature request
  • This feature might incur a breaking change

AWS Java SDK version used

2.29.45

JDK version used

Temurin-21.0.3+9

Operating System and version

macOs Sequoia 15.3.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature-requestA feature should be added or improved.needs-triageThis issue or PR still needs to be triaged.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions