Last active
October 16, 2024 13:46
-
-
Save abferm/54eabfc74a77394099b22c73a152f32f to your computer and use it in GitHub Desktop.
Bash script for executing with AWS SSM parameters exported as environment variables. Useful as an entrypoint for docker containers intended to run in ecs
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 | |
# | |
# | |
# | |
ssm_available() { | |
if [ -z ${SSM_BASE_PATH+x} ]; then | |
return 1 | |
fi | |
return 0 | |
} | |
get_ssm_params() { | |
aws ssm get-parameters-by-path --no-paginate --path ${SSM_BASE_PATH} --with-decryption --query Parameters | \ | |
jq -r 'map("\(.Name | sub("'${SSM_BASE_PATH}'";""))=\(.Value)") | join("\n")' | |
} | |
exec_with_ssm_parameters() { | |
for parameter in `get_ssm_params`; do | |
echo "Info: Exporting parameter ${parameter%%=*}" | |
export ${parameter} | |
done | |
exec "$@" | |
} | |
main() { | |
if ssm_available; then | |
echo "Info: Loading SSM Parameters" >&2 | |
exec_with_ssm_parameters "$@" | |
fi | |
echo "Info: Starting ..." >&2 | |
exec "$@" | |
} | |
main "$@" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment