forked from bash-my-aws/bash-my-aws
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtarget-group-functions
71 lines (62 loc) · 1.81 KB
/
target-group-functions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/bin/bash
#
# target-group-functions
#
# Load balancer target groups
target-groups() {
# List EC2 ELBv2 target groups
#
# $ target-groups
# bash-my-aws-nlb-tg TCP 22 vpc-04636ebe5573f6f65 instance bash-my-aws-nlb
# bash-my-aws-alb-tg HTTP 443 vpc-04636ebe5573f6f65 instance bash-my-aws-alb
local tg_names=$(skim-stdin)
local filters=$(__bma_read_filters $@)
aws elbv2 describe-target-groups \
${tg_names/#/'--names '} \
--output text \
--query "
TargetGroups[][
TargetGroupName,
Protocol,
Port,
VpcId,
TargetType,
join(' ', LoadBalancerArns[])
]" |
sed 's,arn:[^/]*:loadbalancer/[^/]*/\([^/]*\)[^[:blank:]]*,\1,g' |
grep -E -- "$filters" |
LC_ALL=C sort -b |
columnise
}
target-group-targets() {
# List EC2 ELBv2 target group targets
# Accepts Target Group names on stdin or as arguments
#
# $ target-group-targets bash-my-aws-nlb-tg
# i-4e15ece1de1a3f869 443 healthy bash-my-aws-nlb-tg
# i-89cefa9403373d7a5 443 unhealthy bash-my-aws-nlb-tg
local tg_names=$(skim-stdin "$@")
[[ -z $tg_names ]] && __bma_usage "tg-name [tg-name]" && return 1
for tg_name in $tg_names; do
local tg_arn=$(aws elbv2 describe-target-groups \
--names "$tg_name" \
--output text \
--query "
TargetGroups[][
TargetGroupArn
]
")
aws elbv2 describe-target-health \
--target-group-arn "$tg_arn" \
--output text \
--query "
TargetHealthDescriptions[][
Target.Id,
Target.Port,
TargetHealth.State,
TargetHealth.Description,
'${tg_name}'
]
"
done | columnise
}