Read more

Manage your AWS credentials for multiple accounts

Kim Klotz
April 23, 2013Software engineer at makandra GmbH

Create a directory mkdir ~/.aws

Illustration UI/UX Design

UI/UX Design by makandra brand

We make sure that your target audience has the best possible experience with your digital product. You get:

  • Design tailored to your audience
  • Proven processes customized to your needs
  • An expert team of experienced designers
Read more Show archive.org snapshot

Initialise git repository cd ~/.aws && git init

Create a git branch with a name you want (e.g. development for the aws development account credentials).

Add AWS credential file .aws_credentials:

AWSAccessKeyId=ABCDEFG1234
AWSSecretKey=4321GFEDCBA

Also add your EC2 cert and private key file.
You can add other AWS account depending files like .fog or .guignol.yml too.

Create symlinks for some config files like .aws_credentials and .fog:

ln -s ~/.aws/.aws_credentials ~/.aws_credentials
ln -s ~/.aws/.fog ~/.fog

If you want to manage a new account you just have to add a new git branch.

Add this to your bashrc:

export EC2_PRIVATE_KEY=~/.aws/pk-ec2.pem
export EC2_CERT=~/.aws/cert-ec2.pem
export AWS_CREDENTIAL_FILE=~/.aws/aws-credentials

Perhaps you also want to set a default region and the JAVA_HOME:

export EC2_REGION=eu-west-1
export EC2_URL=https://eu-west-1.ec2.amazonaws.com
export JAVA_HOME=/usr

Add a bash script somewhere in your $PATH (I called it am):

#!/bin/bash
if [[ $1 == "list" ]]; then
  cd ~/.aws && git branch -l
elif [[ $1 != "" && `cd ~/.aws && git branch | grep $1` ]]; then
  cd ~/.aws && git checkout $1 > /dev/null
  echo "Ready to Manage $1!"
else
  echo "$1 is not a valid ec2 branch"
fi

Now you can easly manage different AWS accounts and choose it with am branchname.

Posted by Kim Klotz to makandra dev (2013-04-23 14:15)