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 you export 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 my zsh dotfiles3.

AWS Profiles


  1. .zshrc in my case

  2. i.e. current value of AWS_DEFAULT_PROFILE

  3. green: current git branch; yellow: AWS_DEFAULT_PROFILE; red: current ruby version set by rbenv