Category Archives: Bash

Manage Multiple AWS Accounts Using Direnv

Mad Hacker SkillsI came across a simple yet elegant means of managing multiple Amazon Web Services credentials when using the AWS CLI. This way does not make you have to hack your .aws/config and is the simplest/cleanest way I have found.

First install direnv and make sure it is in your PATH.

Be sure to remember to add the hook to your shell of choice as they outline in their README.

Now that you have direnv setup we can configure it for each client.

I use a directory structure to keep each client in their own directory.

So for example in : .../clients/ACME/ I make a .envrc file and export my AWS keys in it:

export AWS_ACCESS_KEY_ID=****

Once you make your .envrc file run direnv allow to enable using the config. Then test your AWS CLI to insure working properly.

Then when you are doing work on that client’s account you simply have to cd into their respective directory.

Be sure to either encrypt the whole directory or at least chmod 600 the .envrc files to protect your keys.