-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdelete-docdb-cluster.bash
executable file
·42 lines (33 loc) · 1.03 KB
/
delete-docdb-cluster.bash
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
# make sure user passed cluster identifier
if [ $# -ne 1 ] ; then
echo "1 argument required: <cluster-identifier>"
exit 1
fi
DDB_DB_CLUSTER_IDENTIFIER=$1
clusterInfo=`aws docdb describe-db-clusters \
--db-cluster-identifier $DDB_DB_CLUSTER_IDENTIFIER \
--query 'DBClusters[*].[DBClusterIdentifier,DBClusterMembers[*].DBInstanceIdentifier]'
`
#echo $clusterInfo
COUNTER=0
while [ $COUNTER -lt 16 ]; do
thisInstance=`echo $clusterInfo | jq -c ".[][1][${COUNTER}]" | tr -d '"'`
if [ "$thisInstance" = "null" ]; then
# no more instances, exit loop
COUNTER=16
else
# delete the instance
echo "... deleting instance $thisInstance"
instanceInfo=`aws docdb delete-db-instance \
--db-instance-identifier $thisInstance`
fi
let COUNTER=COUNTER+1
done
sleep 15
echo "... deleting cluster $DDB_DB_CLUSTER_IDENTIFIER"
clusterDeleteInfo=`aws docdb delete-db-cluster \
--db-cluster-identifier $DDB_DB_CLUSTER_IDENTIFIER \
--skip-final-snapshot
`
sleep 15