-
Notifications
You must be signed in to change notification settings - Fork 1
/
aws-list-lbs.sh
executable file
·42 lines (34 loc) · 1.04 KB
/
aws-list-lbs.sh
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
#!/bin/bash
# Parse arguments:
VERBOSE=0
while getopts ":r:p:v" opt; do
case $opt in
r) REGION="--region $OPTARG";;
p) PROFILE="--profile $OPTARG";;
v) VERBOSE=$(( VERBOSE + 1 ));;
:) echo "Option -$OPTARG requires an argument." >&2; exit 1;;
\?) echo "Invalid option: -$OPTARG" >&2;;
esac
done
shift $((OPTIND-1))
if ! which jq > /dev/null 2>&1; then echo "The 'jq' command is not installed, aborting." >&2; exit 1; fi
if [[ "$VERBOSE" == 0 ]]; then
aws $PROFILE $REGION elb describe-load-balancers | jq -r '.LoadBalancerDescriptions[].LoadBalancerName' | sort
exit $?
fi
if [[ "$VERBOSE" == 2 ]]; then
aws $PROFILE $REGION elb describe-load-balancers
exit $?
fi
if [[ "$VERBOSE" == 1 ]]; then
aws $PROFILE $REGION elb describe-load-balancers \
| jq -r '
.LoadBalancerDescriptions[]
| .DNSName as $dns
| .LoadBalancerName as $name
| .ListenerDescriptions[]
| (if (.Listener.Protocol == "HTTP") then "http://\($dns)/" else "https://\($dns)" end) as $url
| "\($name) \($url)"
'
exit $?
fi