Last active
April 29, 2019 13:17
-
-
Save oliwer/32f1cff778cee17f0b35867b6f891b65 to your computer and use it in GitHub Desktop.
Script to set the current AWS profile
This file contains hidden or 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 -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