Blog
Easily Switch AWS Profiles with Tab Completion
Tired of manually switching AWS profiles? This short bash function adds an aps command with tab completion for all your existing AWS config profiles. Just drop it in your ~/.bash_profile and go.
Feb 6, 2020

I am constantly moving between AWS profiles and wrote a bash function to help me hop between what I need.
Hopefully, someone else finds it useful
#!/bin/bash
_getprofiles() {
COMPREPLY=($(compgen -W "$(sed -n 's#^\[\(.*\)\]#\1#p' ~/.aws/credentials | sort -u)" -- "${COMP_WORDS[1]}"))
}
aps () {
if [ -z "$1" ]; then
echo $AWS_DEFAULT_PROFILE
return
fi
export AWS_DEFAULT_PROFILE=$1
}
complete -F _getprofiles apsJust put that function into your ~/.bash_profile or something that is sourced when a terminal session starts.
This will add the command aps and you can tab complete any of the existing profiles in your aws config.
We’ll use the information you provide to respond to your enquiry. Learn more about how we handle your personal data in our Privacy Policy.
/Contact Us

Modernize your legacy with Focused
Get in touch