DescribeInstanceHealth 搭配 CLI 使用 - AWS SDK 程式碼範例

文件 AWS SDK AWS 範例 SDK 儲存庫中有更多可用的 GitHub 範例。

本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。

DescribeInstanceHealth 搭配 CLI 使用

下列程式碼範例示範如何使用 DescribeInstanceHealth

CLI
AWS CLI

描述負載平衡器執行個體的運作狀態

此範例說明指定負載平衡器執行個體的運作狀態。

命令:

aws elb describe-instance-health --load-balancer-name my-load-balancer

輸出:

{ "InstanceStates": [ { "InstanceId": "i-207d9717", "ReasonCode": "N/A", "State": "InService", "Description": "N/A" }, { "InstanceId": "i-afefb49b", "ReasonCode": "N/A", "State": "InService", "Description": "N/A" } ] }

描述負載平衡器執行個體的運作狀態

此範例說明指定負載平衡器之指定執行個體的運作狀態。

命令:

aws elb describe-instance-health --load-balancer-name my-load-balancer --instances i-7299c809

以下是正在註冊之執行個體的範例回應。

輸出:

{ "InstanceStates": [ { "InstanceId": "i-7299c809", "ReasonCode": "ELB", "State": "OutOfService", "Description": "Instance registration is still in progress." } ] }

以下是運作狀態不佳執行個體的範例回應。

輸出:

{ "InstanceStates": [ { "InstanceId": "i-7299c809", "ReasonCode": "Instance", "State": "OutOfService", "Description": "Instance has failed at least the UnhealthyThreshold number of health checks consecutively." } ] }
PowerShell
for PowerShell 工具

範例 1:此範例說明向指定負載平衡器註冊的執行個體狀態。

Get-ELBInstanceHealth -LoadBalancerName my-load-balancer

輸出:

Description InstanceId ReasonCode State ----------- ---------- ---------- ----- N/A i-87654321 N/A InService Instance has failed at lea... i-12345678 Instance OutOfService

範例 2:此範例說明向指定負載平衡器註冊的指定執行個體狀態。

Get-ELBInstanceHealth -LoadBalancerName my-load-balancer -Instance i-12345678

範例 3:此範例會顯示指定執行個體狀態的完整描述。

(Get-ELBInstanceHealth -LoadBalancerName my-load-balancer -Instance i-12345678).Description

輸出:

Instance has failed at least the UnhealthyThreshold number of health checks consecutively.