Bootstrap FreeKB - Amazon Web Services (AWS) - List Target Group Health Status using the AWS CLI
Amazon Web Services (AWS) - List Target Group Health Status using the AWS CLI


An Elastic Load Balancer (ELB) is typically used to load balance requests across two (or more) different EC2 instances. 

 

This assumes you have already configured the aws command line tool. If not, check out my article on Getting Started with the AWS CLI.

Let's say you have registered targets in a Target Group and you want to check the health of the Target Group. First you will want to use the aws elbv2 describe-target-groups command to get the ARN (Amazon Resource Name) of the target group.

~]$ aws elbv2 describe-target-groups
{
    "TargetGroups": [
        {
            "TargetGroupArn": "arn:aws:elasticloadbalancing:us-east-1:123456789012:targetgroup/my-target-group/b12348d3a5abcd1d",
            "TargetGroupName": "my-target-group",
            "Protocol": "HTTP",
            "Port": 80,
            "VpcId": "vpc-0141234fa33abcd01",
            "HealthCheckProtocol": "HTTP",
            "HealthCheckPort": "traffic-port",
            "HealthCheckEnabled": true,
            "HealthCheckIntervalSeconds": 30,
            "HealthCheckTimeoutSeconds": 5,
            "HealthyThresholdCount": 5,
            "UnhealthyThresholdCount": 2,
            "HealthCheckPath": "/",
            "Matcher": {
                "HttpCode": "200"
            },
            "LoadBalancerArns": [],
            "TargetType": "instance",
            "ProtocolVersion": "HTTP1",
            "IpAddressType": "ipv4"
        }
    ]
}
 

 

Then the aws elbv2 describe-target-health command can be used to get the health status of the Target Group.

~]$ aws elbv2 describe-target-health --target-group-arn arn:aws:elasticloadbalancing:us-east-1:123456789012:targetgroup/my-target-group/b12348d3a5abcd1d
{
    "TargetHealthDescriptions": [
        {
            "Target": {
                "Id": "i-abcdefg0123456789",
                "Port": 80
            },
            "HealthCheckPort": "80",
            "TargetHealth": {
                "State": "healthy"
            }
        }
    ]
}

 

Check out my article Resolve "Target group is not configured to receive traffic from the load balancer" if something like this is being returned.

{
    "TargetHealthDescriptions": [
        {
            "Target": {
                "Id": "i-0182deb20171e5945",
                "Port": 80
            },
            "HealthCheckPort": "80",
            "TargetHealth": {
                "State": "unused",
                "Reason": "Target.NotInUse",
                "Description": "Target group is not configured to receive traffic from the load balancer"
            }
        },
        {
            "Target": {
                "Id": "i-0f9a8d82897695a66",
                "Port": 80
            },
            "HealthCheckPort": "80",
            "TargetHealth": {
                "State": "unused",
                "Reason": "Target.NotInUse",
                "Description": "Target group is not configured to receive traffic from the load balancer"
            }
        }
    ]
}

 




Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee



Comments


Add a Comment


Please enter 5a411b in the box below so that we can be sure you are a human.