2013-05-15 119 views
2

當某個實例啓動時,aws控制檯顯示兩列狀態和狀態檢查。運行狀態不是狀態的真實反映,因爲狀態檢查可能會失敗。AWS:如何獲取實例狀態檢查狀態,而不是狀態

任何人都有.net C#代碼檢查狀態檢查狀態的任何示例?

我最接近的是這樣的:

var request = new DescribeInstanceStatusRequest(); 
     request.InstanceId = insts.Select(i => i.InstanceId).ToList(); 
     DescribeInstanceStatusResponse response = ec2Client.DescribeInstanceStatus(request); 

     InstanceStatus instanceStatus = response.DescribeInstanceStatusResult.InstanceStatus[0]; 
     Console.WriteLine("Availability zone - " + instanceStatus.AvailabilityZone); 
     Console.WriteLine("Instance State Code - " + instanceStatus.InstanceState.Code); 
     Console.WriteLine("Instance State Name - " + instanceStatus.InstanceState.Name); 

     foreach (InstanceStatusEvent statusEvent in instanceStatus.InstanceStatusEvent) 
     { 
      Console.WriteLine("Event Code - " + statusEvent.Code); 
      Console.WriteLine("Event Description - " + statusEvent.Description); 
      Console.WriteLine("Earliest Scheduled Start Time - " + statusEvent.NotBefore); 
      Console.WriteLine("Latest Scheduled End Time - " + statusEvent.NotAfter); 
     } 

但只是給國家,而不是狀態檢查。

+0

當前代碼打印什麼? – Undo

+0

它打印「運行」,但這不是我所需要的,我需要「狀態檢查」字段狀態,因爲它們可能會失敗,並且實例init會出錯。 – user1013388

回答

2

您需要深入瞭解InstanceStatus對象。狀態檢查位於InstanceStatusDetailSystemStatusDetail屬性中。下面是一個爲你獲取該信息的代碼片段:

 var status = result.InstanceStatus[0]; 
     Console.WriteLine("Instance Status = " + status.InstanceStatusDetail.Status); 
     Console.WriteLine("Instance Status Detail Name = " + status.InstanceStatusDetail.Detail[0].Name); 
     Console.WriteLine("Instance Status Detail Status = " + status.InstanceStatusDetail.Detail[0].Status); 
     Console.WriteLine("System Status = " + status.SystemStatusDetail.Status); 
     Console.WriteLine("System Status Detail Name = " + status.SystemStatusDetail.Detail[0].Name); 
     Console.WriteLine("System Status Detail Status = " + status.SystemStatusDetail.Detail[0].Status); 
+0

+即使知道在哪裏看,這是一個混亂。 – Basic