Juggling Multiple AWS Profiles
I interact with multiple, disparate AWS profiles every day via the aws
CLI tool. Here's how I ensure my aws
commands end up in the right place:
- Don't set a default profile as far as the
.aws
configuration files are concerned; instead use a set of several named profiles. My~/.aws/config
and~/.aws/credentials
files list the same set of profiles; none are set to default. - Instead, for a particular shell instance, set your working profile via the
AWS_DEFAULT_PROFILE
variable. Make sure youexport
it; i.e.export AWS_DEFAULT_PROFILE=foo
. If you want to switch profiles in a given shell, just re-export
the variable to a different profile name. - Give your shell a default profile by
export
-ing this variable in your.bashrc
or whatever the relevant shell init file may be1. - Ensure the current active profile2 is visible at all times in your shell so you always know what you're working with. I do this by setting the
RPROMPT
in myzsh
dotfiles3.