Created
May 28, 2019 17:03
-
-
Save yeukhon/b3f0e651e07997d0671e44f95f436679 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# This script takes two arguments: rds database identifier and timeout. | |
DB_ID=$1 | |
TIMEOUT=$2 | |
POLL_INTERVAL=60 | |
OK_STATES=("backing-up" "available" "modifying" "resetting-master-credentials") | |
seconds_left=$TIMEOUT | |
while [[ "${seconds_left}" -gt 0 ]] | |
do | |
db_status=$(aws rds describe-db-instances --db-instance-identifier $DB_ID --query 'DBInstances[0].[DBInstanceStatus]' --output text) | |
if [[ "${OK_STATES[@]} " =~ "${db_status}" ]]; then | |
sleep 120 | |
exit 0 | |
else | |
seconds_left="$((${seconds_left} - ${POLL_INTERVAL}))" | |
sleep ${POLL_INTERVAL} | |
fi | |
done | |
# Time exceeded here | |
exit 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment