DEV Community

andrea
andrea

Posted on

AWS profile chooser

Super short AWS hint.

Having different AWS profiles, I do not want to pick default one just because I forgot --profile command line option.

Just looking for a way of forcing me having to choose an AWS profile before issuing any command.

My solution was (for bash only):

  1. Removing default profile in ~/.aws/credentials
    No command will work from now on without a --profile or an AWS_PROFILE environment variable

  2. Creating a one-liner alias for choosing the desired profile and setting $AWS_PROFILE environment variable.

    An alias let me reuse the same shell I'm in.

alias aws-profile-chooser='x() { select prof in $( aws configure list-profiles ) ; do  export AWS_PROFILE="$prof"; break; done }; x'
Enter fullscreen mode Exit fullscreen mode

(you can see the gist here)

This command will show me available profiles, and after choosing the right one, it will set AWS_PROFILE environment variable.

$ aws-profile-choose 
1) default
2) amplify-udemy
3) aws-lambda-deploy
4) test-aws
#?
Enter fullscreen mode Exit fullscreen mode

From now on if I forget to choose a profile, any command will break.

Choosing and setting an AWS profile...is now a breeze! ;)

Top comments (0)