Created
August 7, 2018 13:41
-
-
Save kubek2k/b68c62a920f1aab5050db56f9db61ed1 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
aws rds describe-db-instances | jq '.DBInstances[] | "" + .DBInstanceIdentifier + " " + .MasterUsername + " " + .Endpoint.Address' -r | grep pro > hosts |
This file contains hidden or 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 | |
set -e | |
DB_ID=$1 | |
USER=$2 | |
HOSTNAME=$3 | |
PASS=`pwgen 10 1` | |
aws rds modify-db-instance --db-instance-identifier $DB_ID --master-user-password $PASS > /dev/null | |
CONNECTION_URL="postgres://${USER}:${PASS}@${HOSTNAME}/postgres" | |
echo "$CONNECTION_URL" | |
echo "Sleeping for 30s to make password change effective" | |
sleep 30 | |
echo -e "CREATE DATABASE \"ad-manager\";\nGRANT ALL PRIVILEGES ON DATABASE \"ad-manager\" TO $USER;\nCREATE DATABASE pusher;\nGRANT ALL PRIVILEGES ON DATABASE pusher TO $USER;\nCREATE DATABASE settings;\nGRANT ALL PRIVILEGES ON DATABASE settings TO $USER;\nCREATE DATABASE content;\nGRANT ALL PRIVILEGES ON DATABASE content TO $USER;\n" | psql "${CONNECTION_URL}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment