0

I am trying to create an instance in AWS EC2 but the line

RunInstancesResponse launchResponse = ec2Client.RunInstances(launchRequest); 

causes an exception:

AmazonEC2Client.RunInstances(RunInstanceRequest) is inaccessible due to it's protection level

Below is my code. I've tried using RunInstanceAsync instead but it also didn't work.

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);
}
Philip Pittle
  • 11,821
  • 8
  • 59
  • 123

1 Answers1

-1

I think you are using the .NET Core version of the SDK. In .NET Core only the async operations are supported. So you need to call RunInstancesAsync.

Norm Johanson
  • 2,964
  • 14
  • 13