Skip to content

Instantly share code, notes, and snippets.

@vukasin-nikodijevic
Created April 21, 2020 17:34
Show Gist options
  • Save vukasin-nikodijevic/05b411712746d1e9136264f4a2c17dd7 to your computer and use it in GitHub Desktop.
Save vukasin-nikodijevic/05b411712746d1e9136264f4a2c17dd7 to your computer and use it in GitHub Desktop.
AWS CLI Profile Switcher
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