Bootstrap FreeKB - Amazon Web Services (AWS) - Deregister Targets in a Target Group using the AWS CLI
Amazon Web Services (AWS) - Deregister Targets in a Target Group 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've a Target Group named my-target-group that already has one or more EC2 instance registered in the Target Group. The aws elbv2 describe-target-health command can be used to see that the EC2 instances have been registered in the Target Group.

~]$ aws elbv2 describe-target-health --target-group-arn arn:aws:elasticloadbalancing:us-east-1:713512344252:targetgroup/my-target-group/b12348d3a5abcd1d
{
    "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"
            }
        }
    ]
}

 

The aws elbv2 deregister-targets command can then be used the Deregister (remove) the EC2 instances from the Target Group.

aws elbv2 deregister-targets 
--target-group-arn arn:aws:elasticloadbalancing:us-east-1:713512344252:targetgroup/my-target-group/b12348d3a5abcd1d
--targets Id=i-0f9a8d82897695a66 Id=i-0182deb20171e5945



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 5cd62d in the box below so that we can be sure you are a human.