Last active
January 3, 2024 20:30
-
-
Save zdk/11101f1a4172487b2ae5841500ae32e9 to your computer and use it in GitHub Desktop.
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 | |
set -e | |
SECRETS_MANAGER="aws secretsmanager" | |
REGION="ap-southeast-1" | |
function get_secret { | |
$($SECRETS_MANAGER get-secret-value --secret-id $secret --query SecretString --output text --region $REGION) | |
} | |
function parse_secret { | |
jq -r 'to_entries[] | "export \(.key)='\''\(.value)'\''"' | |
} | |
read -r -a secrets <<< "$SECRETS" | |
for secret in "${secrets[@]}" | |
do | |
export_vars=$(get_secret | parse_secret) | |
eval $export_vars | |
done | |
exec "$@" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I had to put this down for a few days, but the last thing I had to do to get it working was put
echo
in front of the whole command on line7
. Otherwise, it would return with{"KEY":"value"}: command not found
. After that last change the script works perfectly. 🎉Thank you @zdk for posting this. 😄