Skip to content

Instantly share code, notes, and snippets.

@oremj
Last active August 29, 2015 14:00
Show Gist options
  • Save oremj/1d62e6c0354ccf3877d7 to your computer and use it in GitHub Desktop.
Save oremj/1d62e6c0354ccf3877d7 to your computer and use it in GitHub Desktop.
Switch between encrypted AWS environments.
# -*- mode: shell-script -*-
# source this file from your shell's rc file
activate_aws_env() {
AWS_ENV=$1
ENV_FILE="${HOME}/Dropbox/awsenvs/${AWS_ENV}.gpg"
if [ ! -f "$ENV_FILE" ]; then
echo "$ENV_FILE" does not exist.
return
fi
OUT=$(gpg -d "$ENV_FILE")
eval "$OUT"
}
#!/bin/bash
set -e
set -o nounset
AWS_ENV=$1
mkdir -p "${HOME}/Dropbox/awsenvs"
ENV_FILE="${HOME}/Dropbox/awsenvs/${AWS_ENV}.gpg"
if [[ -f "$ENV_FILE" ]]; then
echo "env already exists"
exit 1
fi
read -p "Key id: " AWS_ACCESS_KEY_ID
read -p "Key secret: " AWS_SECRET_ACCESS_KEY
gpg -c -o "$ENV_FILE" <<ENVDOC
export AWS_ACCESS_KEY_ID=${AWS_ACCESS_KEY_ID}
export AWS_SECRET_ACCESS_KEY=${AWS_SECRET_ACCESS_KEY}
ENVDOC
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment