Created
February 17, 2020 06:06
-
-
Save michaelgreenhill/f3c2fbee1a854c8f1b504d7dee1b4dd4 to your computer and use it in GitHub Desktop.
Export an AWS secret to a .env file
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
#!/bin/bash | |
AWS_SECRET_ID="my-super-secret-secret" | |
AWS_REGION="ap-southeast-2" | |
ENVFILE="/srv/app/.env" | |
# Ensure your EC2 instance has the most recent version of the AWS CLI | |
apt-get install -y python3-pip jq | |
pip3 install awscli --upgrade | |
# Export the secret to .env | |
aws secretsmanager get-secret-value --secret-id $AWS_SECRET_ID --region $AWS_REGION | \ | |
jq -r '.SecretString' | \ | |
jq -r "to_entries|map(\"\(.key)=\\\"\(.value|tostring)\\\"\")|.[]" > $ENVFILE |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment