5

Direnv with multiple AWS Accounts

 3 years ago
source link: https://zoph.me/posts/2017-01-10-direnv-with-aws/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client
Jan 10, 2017

Direnv with multiple AWS Accounts

If you are working closely with AWS, with multiple customers, multiple accounts, you will love this app : Direnv.

Direnv will let you switch environment variables depending on the current folder you are browsing. It will be especially useful when you are using multi-customers AWS CLI ACCESS_KEY variables. Then you don’t need to run aws configure each time you need to switch credentials.

When you leave the path, direnv will unload variables, then you avoid any mistakes.

First, install direnv (macOS in my case):

brew install direnv

Available, on Linux, Windows (Cigwin).

Second, you need to create a .envrc file:

In the target directory, for example, the name of your customer, organize one folder per customer. create the .envrc file.

- AWS
-- Customer1
-- Customer2
-- Customer3

Fill it with your AWS_ACCESS_KEY and SECRET_ACCESS_KEY, and don’t forget to `chmod 600 at least.

cd /path/to/your/customer/folder
vim .envrc
export AWS_ACCESS_KEY_ID=YOU_AWSOME_ACCESS_ID
export AWS_SECRET_ACCESS_KEY=YOU_AWSOME_SECRET_ACCESS_KEY

Third, install the hook:

In your .bash_profile file, add the following.

eval "$(direnv hook bash)"

Fourth, allow your directory:

cd /path/to/your/customer/folder
direnv allow .

for the child folders, just create .envrc with:

source_env ..

and so on…

That’s all folks!

zoph.


awsawscliunixcli

192 Words

2017-01-10 20:31 +0000


Recommend

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK