Skip to content

Commit

Permalink
Add mechanism to preserve seleect Aurora DB clusters overnight (#451)
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanemerson authored Jul 25, 2023
1 parent d76311e commit c63529d
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion provision/aws/rds/aurora_cluster_reaper.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ if [[ "$RUNNER_DEBUG" == "1" ]]; then
set -x
fi

# Removes all Aurora DB clusters that are not tagged with the key "keepalive"
# To tag an Aurora Cluster with "keepalive" execute:
# `aws rds add-tags-to-resource --resource-name <arn> --tags Key=keepalive --region <region>`
# Where the `<arn>` is the arn of the DB cluster

SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
source ${SCRIPT_DIR}/aurora_common.sh

Expand All @@ -24,7 +29,18 @@ for REGION in ${REGIONS}; do
echo ${DB_INSTANCES} | jq -c '.[]' | while read i; do
export AURORA_CLUSTER=$(echo $i | jq -r .DBClusterIdentifier)
export AURORA_INSTANCE=$(echo $i | jq -r .DBInstanceIdentifier)
sh ${SCRIPT_DIR}/aurora_delete.sh

KEEP_ALIVE=$(aws rds describe-db-clusters \
--region ${REGION} \
--db-cluster-identifier ${AURORA_CLUSTER} \
--query DBClusters[*].TagList[?key=='keepalive'] \
--output json \
| jq -c '.[]' \
| jq length
)
if [ ${KEEP_ALIVE} == "0" ]; then
sh ${SCRIPT_DIR}/aurora_delete.sh
fi
done
fi
done

0 comments on commit c63529d

Please sign in to comment.