Skip to content

Instantly share code, notes, and snippets.

@jviall
Created February 25, 2026 21:13
Show Gist options
  • Select an option

  • Save jviall/54b59bb059f4508d066ba804296a9a27 to your computer and use it in GitHub Desktop.

Select an option

Save jviall/54b59bb059f4508d066ba804296a9a27 to your computer and use it in GitHub Desktop.
A helper Bash/Zsh function/alias to quickly switch between existing AWS Profiles, and log in to them.
# what is my active AWS Profile?
alias awswho='aws sts get-caller-identity'
# Start a fresh session with my active AWS Profile
alias awslogin='aws sso login'
# Switch my active AWS Profile: e.g. `awsp res-dev`
function awsp() {
if [ -z "$1" ]; then
echo "Usage: awsp <profile-name>"
echo "Available profiles:"
aws configure list-profiles
echo "Current profile:"
echo "'$AWS_PROFILE'"
return 1
fi
# Check if profile exists
if ! aws configure list-profiles | grep -q "^$1$"; then
echo "Error: Profile '$1' not found"
echo "Available profiles:"
aws configure list-profiles
return 1
fi
local profile_name="$1"
export AWS_PROFILE="$profile_name"
echo "Switched to profile: '$1'"
#awslogin # uncomment if you'd like awsp to automatically run the login command after switching
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment