Skip to content

Instantly share code, notes, and snippets.

@tmiller
Forked from zonywhoop/with-params
Created May 30, 2025 20:08
Show Gist options
  • Save tmiller/7c19e1a735796871e3a48a4813ad8b24 to your computer and use it in GitHub Desktop.
Save tmiller/7c19e1a735796871e3a48a4813ad8b24 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
#!/bin/bash
#
#
#
# get-parameters-by-path seems to always max out results to
# adjust this to be more than you need
SSM_MAX_ITEMS=${SSM_MAX_ITEMS:-20}
ssm_available() {
if [ -z ${SSM_BASE_PATH+x} ]; then
return 1
fi
return 0
}
get_ssm_params() {
aws ssm get-parameters-by-path --max-items ${SSM_MAX_ITEMS} --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