Kevin Sullivan
Kevin Sullivan

Reputation: 107

Amazon EC2-DescribeInstances doesn't return InstanceID?

I have a C# program where I am trying to get a list of Instance ID's and populate a comboBox with them. I am trying to use DescribeInstances, here is my code:

DescribeInstancesRequest request = new DescribeInstancesRequest();
List<Amazon.EC2.Model.Reservation> result = m_client.DescribeInstances(request).DescribeInstancesResult.Reservation;
    foreach (Amazon.EC2.Model.Reservation reservation in result)
    {
        instanceCB.Items.Add(reservation.ReservationId);
    }

Where ReservationId is, I would like InstanceId, but it does not seem to be a member of the results returned by DescribeInstances. Is there another function I could use that has this ability?

Thanks

Upvotes: 0

Views: 690

Answers (2)

Erick Smith
Erick Smith

Reputation: 930

List<RunningInstance> instances = runResponse.RunInstancesResult.Reservation.RunningInstance;
List<String> instanceIDs = new List<string>();
foreach (RunningInstance item in instances)
{
    instanceIDs.Add(item.InstanceId);
}

Upvotes: 0

Avichal Badaya
Avichal Badaya

Reputation: 3629

you are not even getting the running instance objects. your code should be something like this :-

foreach (RunningInstance ri in result.RunningInstance)
 {
      instanceCB.Items.Add(ri.InstanceId);
 }

It should work.

Upvotes: 1

Related Questions