Created
August 27, 2020 16:13
-
-
Save awsiv/a94c75f32165408f12d5623bcd49d1c6 to your computer and use it in GitHub Desktop.
Find AWS Target Groups without any registered instances
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
for i in $(aws elbv2 describe-load-balancers --query 'LoadBalancers[*].LoadBalancerArn'| jq -r '.[]'); do | |
tgCount=$(aws elbv2 describe-target-groups --load-balancer-arn "$i" --query 'TargetGroups[*].TargetGroupArn' | jq -r '.[]'|wc -l) | |
if [ "$tgCount" -eq 0 ]; then | |
echo "No TG registered on LB: $i" | |
else | |
for t in $(aws elbv2 describe-target-groups --load-balancer-arn "$i" --query 'TargetGroups[*].TargetGroupArn' | jq -r '.[]'); do | |
instanceCount=$(aws elbv2 describe-target-health --target-group-arn "$t" --query 'TargetHealthDescriptions[*].[Target.Id,TargetHealth.State]' | jq -r '.[]' | wc -l) | |
if [ "$instanceCount" -eq 0 ]; then | |
echo "Empty tg: $t" | |
fi | |
done | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment