-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathaws-list-rds.sh
executable file
·39 lines (32 loc) · 1.07 KB
/
aws-list-rds.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
#!/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 rds describe-db-instances | jq -r '.DBInstances[] | select ( .DBInstanceStatus != "deleting" ) | .DBInstanceIdentifier'
exit 0
fi
if [[ "$VERBOSE" == 1 ]]; then
aws $PROFILE $REGION rds describe-db-instances \
| jq -r '.DBInstances[] | [.DBInstanceIdentifier,.DBInstanceStatus] | @csv'
exit 0
fi
if [[ "$VERBOSE" == 2 ]]; then
aws $PROFILE $REGION rds describe-db-instances \
| jq -r '.DBInstances[] | "\(.DBInstanceIdentifier) \"DB_HOST\": \"\(.Endpoint.Address)\""'
exit 0
fi
if [[ "$VERBOSE" == 3 ]]; then
aws $PROFILE $REGION rds describe-db-instances
exit 0
fi