DEV Community

Austin Vance for Focused

Posted on • Edited on • Originally published at focusedlabs.io

5 1

Easily Switch AWS Profiles with Tab Completion

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 aps

Enter fullscreen mode Exit fullscreen mode

Just 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.

Top comments (0)

Heroku

This site is built on Heroku

Join the ranks of developers at Salesforce, Airbase, DEV, and more who deploy their mission critical applications on Heroku. Sign up today and launch your first app!

Get Started

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay