Skip to content

Instantly share code, notes, and snippets.

@michaelgreenhill
Created February 17, 2020 06:06
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save michaelgreenhill/f3c2fbee1a854c8f1b504d7dee1b4dd4 to your computer and use it in GitHub Desktop.
Save michaelgreenhill/f3c2fbee1a854c8f1b504d7dee1b4dd4 to your computer and use it in GitHub Desktop.
Export an AWS secret to a .env file
#!/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