Skip to content

Instantly share code, notes, and snippets.

@keksipurkki
Created March 15, 2022 08:57
Show Gist options
  • Save keksipurkki/33a67ce1214c1cba575e33d25b5e1e5e to your computer and use it in GitHub Desktop.
Save keksipurkki/33a67ce1214c1cba575e33d25b5e1e5e to your computer and use it in GitHub Desktop.
SSM parameters to .env file
#!/bin/sh
set -e
function usage()
{
echo "Usage: $(basename $0) PATH"
}
function to_env()
{
local prefix=$1
jq -r '"\(.Name)=\(.Value)"' | sed -e "s#$prefix##"
}
function ssm_parameters()
{
aws ssm get-parameters-by-path \
--region eu-central-1 \
--path $path \
--with-decryption \
--recursive
}
function main()
{
local path=$1
if [[ -z "$path" ]]; then
usage
exit 1
fi
ssm_parameters $AWS_PROFILE | jq .Parameters[] | to_env $path/
}
main $@
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment