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 "$@" |
Also, line 17
should have no spaces before/after the =
, or it will produce an error. It should read:
export_vars=$(get_secret | parse_secret)
@charltonstanley Thanks! Updated.
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 line 7
. Otherwise, it would return with {"KEY":"value"}: command not found
. After that last change the script works perfectly. 🎉
Thank you @zdk for posting this. 😄
@charltonstanley Congrats! Happy you got it working, lol. great stuff 😂
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
line
7
has some odd uicode characters present when viewing the gistRaw
, causing the script to error.Here is the clean version of line
7
with the unicode characters replaced: