Skip to content

Instantly share code, notes, and snippets.

@biochimia
Last active December 19, 2015 22:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save biochimia/6028609 to your computer and use it in GitHub Desktop.
Save biochimia/6028609 to your computer and use it in GitHub Desktop.
This is how I manage multiple AWS credentials.
# Author: João Abecasis <joao@comoyo.com>
# Date: 2013-06-19
#
# For each AWS identity, you'll need
#
# ~/.aws-credentials.<identity> -- with AWS credentials (see below)
# ~/.aws.<identity> -- symlink to this script
#
# The file .aws-credentials.<identity> is the canonical source for credentials.
# It's directly used by some AWS tools and it should look like:
#
# AWSAccessKeyId=XXXXXXXXXXXXXXXXXXXX
# AWSSecretKey=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
#
# In bash, load credentials with:
#
# $ source ~/.aws.<identity>
#
aws_identity=$(basename "${BASH_SOURCE[0]}")
aws_identity=${aws_identity#.aws.}
echo "Loading AWS identity: $aws_identity"
# For AutoScaling tools
AWS_CREDENTIAL_FILE=~/.aws-credentials.${aws_identity}
declare $(cat ${AWS_CREDENTIAL_FILE})
# For EC2
AWS_ACCESS_KEY=$AWSAccessKeyId
AWS_SECRET_KEY=$AWSSecretKey
# Default region
AWS_DEFAULT_REGION=eu-west-1
EC2_REGION=${AWS_DEFAULT_REGION}
# Service URLs, for services that don't support EC2_REGION
EC2_URL=https://ec2.${EC2_REGION}.amazonaws.com
export AWS_CREDENTIAL_FILE AWS_ACCESS_KEY AWS_SECRET_KEY AWS_DEFAULT_REGION \
EC2_REGION EC2_URL
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment