Created
April 27, 2020 10:33
-
-
Save RecuencoJones/3c304a7f935d701462d24e71581d59a2 to your computer and use it in GitHub Desktop.
Set AWS_PROFILE in current shell
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
alias aws-profile='. ~/.aws/set-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
#!/usr/bin/env bash | |
_aws_profiles=`cat ${HOME}/.aws/credentials | grep '\[' | tr -d '[]'` | |
_aws_profiles_formatted=`echo ${_aws_profiles} | tr '\n' ' '` | |
if [[ -z $1 ]]; then | |
echo "Missing profile name, should be one of: ${_aws_profiles_formatted}" | |
elif [[ -z `echo "${_aws_profiles}" | grep -e "^${1}$"` ]]; then | |
echo "Profile name does not exist, should be one of: ${_aws_profiles_formatted}" | |
else | |
eval "export AWS_PROFILE=${1:-default}" | |
echo "Now using AWS profile: ${AWS_PROFILE}" | |
fi | |
unset _aws_profiles | |
unset _aws_profiles_formatted |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment