Created
April 21, 2020 17:34
-
-
Save vukasin-nikodijevic/05b411712746d1e9136264f4a2c17dd7 to your computer and use it in GitHub Desktop.
AWS CLI Profile Switcher
This file contains 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
function aws_profile_list { | |
cat ~/.aws/credentials| grep "\[" | sed 's/\(^.\)\(.*\)\(.$\)/\2/gi' | |
} | |
function aws_profile_switch { | |
selected="${1}" | |
if [[ -z $(aws_profile_list | grep "${selected}") ]]; then | |
echo "Selected profile [${selected}] doesn't exists." | |
return | |
fi | |
if [[ -z "${selected}" ]]; then | |
selected="$(aws_profile_list | fzf)" | |
fi | |
profile=$(cat ~/.aws/credentials| grep "${selected}" -A3) | |
export AWS_PROFILE="${selected}" | |
AWS_ACCESS_KEY_ID=$(echo profile|grep "key_id" | sed 's/^. = //gi') | |
AWS_SECRET_ACCESS_KEY=$(echo profile|grep "secret" | sed 's/^. = //gi') | |
} | |
alias asp="aws_profile_switch" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment