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

Jose Martinez picture Jose Martinez · Aug 26, 2018 · Viewed 8.2k times · Source

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?

Answer

Adiii picture Adiii · Aug 26, 2018

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'