Skip to content

Instantly share code, notes, and snippets.

@webdevwilson
Last active February 16, 2018 21:10
Show Gist options
  • Save webdevwilson/6f8e95793c4eaf41f7d0e901a7c9af5d to your computer and use it in GitHub Desktop.
Save webdevwilson/6f8e95793c4eaf41f7d0e901a7c9af5d to your computer and use it in GitHub Desktop.
# Stores vault profile in .aws-vault-profile and provides useful
# commands to use them
#
# aws-vault-get - echo the profile for this directory, searches parent directories
# aws-vault-set <profile> - set the profile for the current directory
# ave <command> - execute a command with the current aws profile
# avl - login to the AWS console with the current profile
# avr - rotate your keys
AWS_VAULT_PROFILE_FILE=".aws-vault-profile"
function aws-vault-get() {
PROFILE_FILE="$(pwd)/${AWS_VAULT_PROFILE_FILE}"
while [ ! -f "${PROFILE_FILE}" ]; do
PROFILE_FILE="$(dirname $(dirname ${PROFILE_FILE}))/${AWS_VAULT_PROFILE_FILE}"
if [ "{PROFILE_FILE}" != "/" ]; then
echo "No aws-vault profile file found ${FILE_NAME}"
return 1
fi
done
printf $(cat ${PROFILE_FILE})
}
function aws-vault-set() {
printf $1 > ./${AWS_VAULT_PROFILE_FILE}
}
function avl() {
PROFILE=$(aws-vault-get)
aws-vault login ${PROFILE}
}
function ave() {
PROFILE=$(aws-vault-get)
aws-vault exec "${PROFILE}" $*
}
function avr() {
PROFILE=$(aws-vault-get)
aws-vault rotate "${PROFILE}" $*
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment