Skip to content

Instantly share code, notes, and snippets.

@oliwer
Last active April 29, 2019 13:17
Show Gist options
  • Save oliwer/32f1cff778cee17f0b35867b6f891b65 to your computer and use it in GitHub Desktop.
Save oliwer/32f1cff778cee17f0b35867b6f891b65 to your computer and use it in GitHub Desktop.
Script to set the current AWS profile
#!/bin/bash -eu
profile=${1:?usage: eval \`awsenv <profile>\`}
xp() { echo export "$*"; }
found=false
while read key eq value; do
if ! $found; then
if [ "$key" = "[$profile]" ]; then
found=true
xp AWS_DEFAULT_PROFILE=$profile
fi
else
case "$key" in
aws_access_key_id|aws_secret_access_key|aws_session_token|aws_keyname|aws_keypath)
xp ${key^^}=$value ;;
ca_bundle) xp AWS_${key^^}=$value ;;
output|region) xp AWS_DEFAULT_${key^^}=$value ;;
""|"[$profile]") ;;
*) found=false ;;
esac
fi
done < ~/.aws/credentials < ~/.aws/config
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment