如何在C#中使用AWS SDK检索AWS-EC2 Windows实例密码 [英] how to retrive aws-ec2 windows instance password using aws sdk in c#

查看:244
本文介绍了如何在C#中使用AWS SDK检索AWS-EC2 Windows实例密码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 aws sdk aws sdk 检索云数据。
我得到了所有与 ec2 相关的数据,但是我无法找到如何连接实例的方法。

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);


推荐答案

首先,您需要一个密钥/对文件创建实例时需要使用它来检索Windows密码。

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.

以下是使用AWS开发工具包检索Windows实例密码的步骤:

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

#1。 您需要将instancepe以及RSA密钥从.pem文件传递到以下代码。

    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;
});

注意:您必须在启动实例后至少等待4分钟才能获取Windows密码。

这篇关于如何在C#中使用AWS SDK检索AWS-EC2 Windows实例密码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆