Amazon EC2-DescribeInstances不会返回InstanceID?

时间:2012-08-22 21:52:12

标签: c# amazon-ec2

我有一个C#程序,我试图获取一个实例ID列表并用它们填充一个comboBox。我正在尝试使用DescribeInstances,这是我的代码:

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

如果是ReservationId,我想要InstanceId,但它似乎不是DescribeInstances返回的结果的成员。还有其他我能用的功能吗?

由于

2 个答案:

答案 0 :(得分:1)

你甚至没有获得正在运行的实例对象。你的代码应该是这样的: -

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

它应该有用。

答案 1 :(得分:0)

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