-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fb10984
commit 536f996
Showing
1 changed file
with
25 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#!/bin/bash | ||
|
||
# Check if required environment variables are set | ||
if [ -z "$AWS_ACCESS_KEY_ID" ] || [ -z "$AWS_SECRET_ACCESS_KEY" ] || [ -z "$AWS_REGION" ] || [ -z "$AWS_SECRETS_ARN" ]; then | ||
echo "Error: Required AWS environment variables are not set." | ||
exit 1 | ||
fi | ||
|
||
# Retrieve the secret from AWS Secrets Manager | ||
secret=$(aws secretsmanager get-secret-value --secret-id "$AWS_SECRETS_ARN" --query SecretString --output text) | ||
|
||
# Check if the secret was retrieved successfully | ||
if [ $? -ne 0 ]; then | ||
echo "Error: Failed to retrieve secret from AWS Secrets Manager." | ||
exit 1 | ||
fi | ||
|
||
# Parse the JSON and export each key/value pair | ||
echo "$secret" | jq -r 'to_entries | .[] | "export \(.key)=\(.value)"' | while read -r line; do | ||
eval "$line" | ||
done | ||
|
||
# Optionally, you can print a success message | ||
echo "AWS secrets have been successfully retrieved and exported to the environment." | ||
|