Forked from PeteGoo/entrypoint-from-ssm-env-vars.sh
Created
September 17, 2019 20:48
-
-
Save xman1980/2699f8c9b2bcea3f3722306f6dfb0234 to your computer and use it in GitHub Desktop.
Helpful SSM Parameter Store scripts
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 | |
# To use just set a variable with SSM_<target_env_var>=<ssm_parameter_store_path> | |
# e.g. SSM_database_password=prod/myservice/database-password | |
function get_parameter { | |
SSM_ENV_VAR_NAME=$1 | |
ENV_VAR_NAME=`echo "$SSM_ENV_VAR_NAME" | cut -c5-` | |
SSM_PARAM_NAME="${!SSM_ENV_VAR_NAME}" | |
echo "Getting parameter $SSM_PARAM_NAME from SSM parameter store if it exists and setting into the variable $ENV_VAR_NAME" | |
SSM_VALUE=`aws ssm get-parameters --with-decryption --names "${SSM_PARAM_NAME}" --query 'Parameters[*].Value' --output text` | |
#echo "SSM_VALUE = $SSM_VALUE" | |
COMMAND="export $ENV_VAR_NAME=$SSM_VALUE" | |
#echo $COMMAND | |
eval ${COMMAND} | |
#echo "$ENV_VAR_NAME = ${!ENV_VAR_NAME}" | |
} | |
while read name ; do | |
get_parameter $name | |
done <<EOT | |
$(printenv | grep -o '^SSM_[^=]*') | |
EOT | |
exec "$@" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment