DEV Community

andrea
andrea

Posted on

1 2

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! ;)

Image of Datadog

The Essential Toolkit for Front-end Developers

Take a user-centric approach to front-end monitoring that evolves alongside increasingly complex frameworks and single-page applications.

Get The Kit

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

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

Okay