我有一个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返回的结果的成员。还有其他我能用的功能吗?
由于
答案 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);
}