Created
June 27, 2019 16:51
-
-
Save udhos/aa95a6fa17672717a0a3d4cd990cfc7c to your computer and use it in GitHub Desktop.
aws-parameter-store
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 | |
env_is_prod() { | |
local instance_id=$(ec2-metadata -i | cut -d ' ' -f2) | |
local tag=$(aws ec2 describe-tags --region sa-east-1 --filter "resource-type=instance" --filter "Name=resource-id,Values=$instance_id" | jq - | |
r '.Tags[] | select(.Key=="env" and .Value=="prod")') | |
[ -n "$tag" ] | |
} | |
if env_is_prod; then | |
param_prefix=/backend/prod/db | |
else | |
param_prefix=/backend/homolog/db | |
fi | |
host=$(aws ssm get-parameters --region sa-east-1 --name $param_prefix/hostname | jq -r '.Parameters[0].Value') | |
db=$(aws ssm get-parameters --region sa-east-1 --name $param_prefix/dbname | jq -r '.Parameters[0].Value') | |
user=$(aws ssm get-parameters --region sa-east-1 --name $param_prefix/master_user | jq -r '.Parameters[0].Value') | |
pass=$(aws ssm get-parameters --region sa-east-1 --name $param_prefix/master_pass --with-decryption | jq -r '.Parameters[0].Value') | |
cat <<__EOF__ | |
DB_HOST=$host | |
DB_NAME=$db | |
DB_USER=$user | |
DB_PASS=$pass | |
__EOF__ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment