Skip to content

Instantly share code, notes, and snippets.

@rodrickbrown
Last active November 16, 2022 15:21
Show Gist options
  • Save rodrickbrown/18b3c855a82ff1ebf0f8fa3e41379778 to your computer and use it in GitHub Desktop.
Save rodrickbrown/18b3c855a82ff1ebf0f8fa3e41379778 to your computer and use it in GitHub Desktop.
rds stop start script
#!/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 ${@}
@cpyadav
Copy link

cpyadav commented Nov 16, 2022

script is not working

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment