【问题标题】:How to create an instace in AWS ec2 through .net SDK如何通过 .net SDK 在 AWS ec2 中创建实例
【发布时间】:2020-07-02 07:54:39
【问题描述】:

我正在尝试在 AWS EC2 中创建一个实例,但是这条线

RunInstancesResponse launchResponse = ec2Client.RunInstances(launchRequest); 

导致异常:

AmazonEC2Client.RunInstances(RunInstanceRequest) 由于其保护级别而无法访问

下面是我的代码。我试过改用RunInstanceAsync,但也没用。

var launchRequest = new RunInstancesRequest()
{
    ImageId = amiID,
    InstanceType = "t2.micro",
    MinCount = 1,
    MaxCount = 1,
    KeyName = keyPairName,
    NetworkInterfaces = enis
};
        
RunInstancesResponse launchResponse = ec2Client.RunInstances(launchRequest);
       
List<String> instanceIds = new List<string>();
        
foreach (Instance instance in launchResponse.Reservation.Instances)
{
    Console.WriteLine(instance.InstanceId);
    instanceIds.Add(instance.InstanceId);
}

【问题讨论】:

  • 您使用的是什么版本的 SDK?你的项目是核心还是框架?

标签: c# .net amazon-ec2 aws-sdk-net


【解决方案1】:

我认为您正在使用 SDK 的 .NET Core 版本。在 .NET Core 中,仅支持异步操作。所以你需要打电话给RunInstancesAsync

【讨论】:

  • 问题不是说已经尝试过但没有用吗?
猜你喜欢
  • 2019-10-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-07-02
  • 1970-01-01
  • 1970-01-01
  • 2018-11-17
相关资源
最近更新 更多