Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to get list of registered targets in AWS target group via CLI

We are trying to get the state of a registered target (instance) in a target group. This can be done with the command aws elbv2 describe-target-health --target-group-arn ${TG} --targets Id=${ID},Port=${PORT}, reference. We are able to get the PORT via the aws ecs describe-tasks --cluster $CLUSTER --tasks $task command, reference. But how can the target's instance Id be retrieved via CLI?

like image 639
Jose Martinez Avatar asked Aug 26 '18 00:08

Jose Martinez


People also ask

How do I find my target group on AWS?

Open the Amazon EC2 console at https://console.aws.amazon.com/ec2/ . On the navigation pane, under LOAD BALANCING, choose Target Groups. Choose the name of the target group to open its details page. On the Targets tab, the Status column indicates the status of each target.

What are EC2 targets?

A target group tells a load balancer where to direct traffic to : EC2 instances, fixed IP addresses; or AWS Lambda functions, amongst others. When creating a load balancer, you create one or more listeners and configure listener rules to direct the traffic to one target group.

How do I get a list of EC2 instances?

Go to the instances section and click on "instances". It will show you all the running instances in the select region.


1 Answers

This will give you the array of registered instance ID in a target group. When you have target ARN why you using target ID? so I am skipping target ID and using just target ARN.

aws elbv2 describe-target-health --target-group-arn ${TG}  --query 'TargetHealthDescriptions[*].Target.Id'
like image 89
Adiii Avatar answered Oct 08 '22 07:10

Adiii