问题描述:

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

网友答案:

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.

网友答案:
List<RunningInstance> instances = runResponse.RunInstancesResult.Reservation.RunningInstance;
List<String> instanceIDs = new List<string>();
foreach (RunningInstance item in instances)
{
    instanceIDs.Add(item.InstanceId);
}
相关阅读:
Top