Skip to content

Instantly share code, notes, and snippets.

@yeukhon
Created May 28, 2019 17:03
Show Gist options
  • Save yeukhon/b3f0e651e07997d0671e44f95f436679 to your computer and use it in GitHub Desktop.
Save yeukhon/b3f0e651e07997d0671e44f95f436679 to your computer and use it in GitHub Desktop.
#!/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