Last active
November 16, 2022 15:21
-
-
Save rodrickbrown/18b3c855a82ff1ebf0f8fa3e41379778 to your computer and use it in GitHub Desktop.
rds stop start script
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 | |
function start-stopRDSInstance { | |
case ${1} in | |
stop) | |
action=stop | |
;; | |
start) | |
action=start | |
;; | |
*) | |
echo "No such action exiting" | |
exit -1 | |
esac | |
databases=$(aws rds describe-db-instances --query 'DBInstances[*].DBInstanceIdentifier' --output text) | |
arn="arn:aws:rds:us-east-1:291674496808:db" | |
for db in ${databases[@]}; | |
do | |
db_env_tag=$(aws rds list-tags-for-resource --resource-name ${arn}:${db} | jq -r '.[][]|select(.Key=="Environment") | .Value') | |
if [[ "${env}" == "${db_env_tag}" ]]; | |
then | |
echo aws rds ${action}-db-instance --db-instance-identifier $db | |
if [[ $? -ne 0 ]]; | |
then | |
echo "fatal error shutting down instance ${db}" | |
fi | |
fi | |
done | |
} | |
function main { | |
action=$1 | |
env=$2 | |
start-stopRDSInstance ${action} ${env} | |
} | |
main ${@} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
script is not working