1

i am able to use AWS SSM CLI to establish a port forwarding connection and open a RDP session with an EC2 instance by using below command.

aws ssm start-session --target <InstanceID> --document-name AWS-StartPortForwardingSession --parameters portNumber="3389","localPortNumber"="1101""

Now i am trying the same with .NET SDK by using class "AmazonSimpleSystemsManagementClient" and callsing "StartSession" method, this method returns a "SessionResponse" class with session id and other parameters.

code is as below.

                var client = new AmazonSimpleSystemsManagementClient(strAccessKeyID,strSecretAccessKey,strSessionToken, RegionEndpoint.USEast1);
                var res = client.GetDocument("AWS-StartPortForwardingSession");
                Amazon.SimpleSystemsManagement.Model.StartSessionRequest request = new Amazon.SimpleSystemsManagement.Model.StartSessionRequest();
                
                Dictionary<string, List<string>> paramDict = new Dictionary<string, List<string>>();
                paramDict.Add("portNumber", new List<string>() { "3389" });
                paramDict.Add("localPortNumber", new List<string> { "1101"});
                var sessionResponse = client.StartSession(new 
                Amazon.SimpleSystemsManagement.Model.StartSessionRequest()
                {
                    DocumentName = "AWS-StartPortForwardingSession",
                    Target = "<InstanceID>",
                    Parameters = paramDict

                }) ;
                Console.WriteLine(sessionResponse.SessionId);

with the above code the session reponse is returning successfully but the issue is not able to open a RDP session. Any idea why RDP is not working?.

thanks, Sarath.

Max Xapi
  • 750
  • 8
  • 22
Sarathbk
  • 11
  • 1
  • Do you need to make the properties Public? – jdweng Nov 18 '20 at 11:01
  • StartSessionResponse contains URL and token you should use to open websocket connection. You should send/receive data in binary format. Unfortunately this protocol is not documented, and they assume we should dig into source code if we want to implement own clients. More detailed answer for JS: https://stackoverflow.com/a/64248831/960055 – Zergatul Aug 12 '22 at 22:54

0 Answers0