There are more AWS SDK examples available in the AWS Doc SDK Examples
Use DescribeInstanceHealth
with a CLI
The following code examples show how to use DescribeInstanceHealth
.
- CLI
-
- AWS CLI
-
To describe the health of the instances for a load balancer
This example describes the health of the instances for the specified load balancer.
Command:
aws elb describe-instance-health --load-balancer-name
my-load-balancer
Output:
{ "InstanceStates": [ { "InstanceId": "i-207d9717", "ReasonCode": "N/A", "State": "InService", "Description": "N/A" }, { "InstanceId": "i-afefb49b", "ReasonCode": "N/A", "State": "InService", "Description": "N/A" } ] }
To describe the health of an instance for a load balancer
This example describes the health of the specified instance for the specified load balancer.
Command:
aws elb describe-instance-health --load-balancer-name
my-load-balancer
--instancesi-7299c809
The following is an example response for an instance that is registering.
Output:
{ "InstanceStates": [ { "InstanceId": "i-7299c809", "ReasonCode": "ELB", "State": "OutOfService", "Description": "Instance registration is still in progress." } ] }
The following is an example response for an unhealthy instance.
Output:
{ "InstanceStates": [ { "InstanceId": "i-7299c809", "ReasonCode": "Instance", "State": "OutOfService", "Description": "Instance has failed at least the UnhealthyThreshold number of health checks consecutively." } ] }
-
For API details, see DescribeInstanceHealth
in AWS CLI Command Reference.
-
- PowerShell
-
- Tools for PowerShell
-
Example 1: This example describes the state of the instances registered with the specified load balancer.
Get-ELBInstanceHealth -LoadBalancerName my-load-balancer
Output:
Description InstanceId ReasonCode State ----------- ---------- ---------- ----- N/A i-87654321 N/A InService Instance has failed at lea... i-12345678 Instance OutOfService
Example 2: This example describes the state of the specified instance registered with the specified load balancer.
Get-ELBInstanceHealth -LoadBalancerName my-load-balancer -Instance i-12345678
Example 3: This example displays the complete description of the state of the specified instance.
(Get-ELBInstanceHealth -LoadBalancerName my-load-balancer -Instance i-12345678).Description
Output:
Instance has failed at least the UnhealthyThreshold number of health checks consecutively.
-
For API details, see DescribeInstanceHealth in AWS Tools for PowerShell Cmdlet Reference.
-