1

I am using aws sdk to retrieve cloud data from aws sdk. I get all ec2 related data but I am not able to find out how to connect instance.

Here is code of retrieve instance from amazon cloud:

IAmazonEC2 ec2Client = new AmazonEC2Client(accesskey,secretkey, new AmazonEC2Config
{
     Timeout = TimeSpan.FromSeconds(300),
     MaxErrorRetry = 3,
     RegionEndpoint = RegionEndpoint.GetBySystemName(regionName)
 });
 var instanceRequest = new DescribeInstancesRequest();
 DescribeInstancesResponse ec2Response = ec2Client.DescribeInstances(instanceRequest);
IanB
  • 3,489
  • 1
  • 20
  • 24
Tejas
  • 21
  • 5

1 Answers1

2

First of you will need a key/pair file that you've used while creating an instance as it is needed to retrieve windows password.

Following are the steps to retrieve windows instance password using AWS SDK:

#1. You need to pass instanceId as well as RSA key from your .pem file to the following code.

    IAmazonEC2 ec2Client = new AmazonEC2Client(accesskey, secretkey, new AmazonEC2Config
     {
                Timeout = TimeSpan.FromSeconds(300),
                MaxErrorRetry = 3,
                RegionEndpoint = region,
     });

     var passwordRequest = new GetPasswordDataRequest();
     passwordRequest.InstanceId = instanceId;
     var passwordResponse = ec2Client.GetPasswordData(passwordRequest);
     var password = passwordResponse.GetDecryptedPassword(rsaKey);
     return password;
});

Note: You have to wait at least 4 minutes after launching an instance to get the windows password.

jbhanderi
  • 53
  • 5
  • 1
    thanks for your answer i will try with this code. but how can i get .prem file. – Tejas Jul 21 '16 at 09:53
  • 1
    i have tried with downloaded .prem file and it working fine.thanks a lot – Tejas Jul 21 '16 at 09:59
  • You will get that only when you create key/pair while launching an instance and you have keep that file at safe place as it will be use for password retrieval in future. There is not other option to download that file. – jbhanderi Jul 21 '16 at 09:59