问题
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);
回答1:
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.
来源:https://stackoverflow.com/questions/38499769/how-to-retrive-aws-ec2-windows-instance-password-using-aws-sdk-in-c-sharp