Skip to content
This repository has been archived by the owner on Apr 8, 2018. It is now read-only.
/ awsenv Public archive

awskeys - AWS API Keys environment variables, à la RVM

Notifications You must be signed in to change notification settings

mv/awsenv

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 

Repository files navigation

AWSenv

AWSenv - A puny little script to enable switching between different AWS API keys for different accounts.

Outdated!

<OBS! OBS! OBS!>

This is outdated. This functionality is now replaced by the new Python based AWS Command Line Interface.

Using the new cli:

aws configure --profile profile1
aws configure --profile profile2
aws configure --profile profile3

Add to your ~/.bashrc

function __aws_config() {
    # add to the prompt:
    [ "${AWS_DEFAULT_PROFILE}" ] && msg="${AWS_DEFAULT_PROFILE}"
    [ "${AWS_DEFAULT_REGION}"  ] && msg="${msg}:${AWS_DEFAULT_REGION}"
    echo "[aws:${msg}]"
}

export DEFAULT_REGION="us-west-2"
export DEFAULT_PROFILE="profile1"

export PS1="\u@h:\w $(__aws_config)\n\$ "

</OBS! OBS! OBS!>

Scenario

If you, like me, work with more than one Amazon AWS account this script will help you by ajusting your environment variables, from one account to another.

Basically, think of RVM.... and you get the idea.

Install

Copy awsenv.sh anywhere in your PATH.

Add to your ~/.bashrc

export AWSENV_PROFILES_DIR="~/work/awsenv/profiles"
source /path/to/awsenv.sh

Reopen your terminal, or login again to activate it.

As an extra, add to your PS1 variable:

export PS1="\u@h:\w $(__awsenv_ps1)\n\$ "

Setup

First you create a profiles dir which is a location to hold all your credentials. For each Amazon account you create a second directory which holds at least 3 files:

- aws-credential-file.cfg
- cert-XXXXX.pem
- pk-XXXXXXX.pem

Those files must be created by you. 'aws-credential-file.cfg' must have the following format:

AWSAccessKeyId=<<your-access-key>>
AWSSecretKey=<<your-secret-key>>

The pk/cert files are a self-signed X509 certificate generated by you. To create such files take a look at generating a X509 by yourself.

You probably will need pk/cert only if you need to use EC2 AMI tools API. For all other usages 'aws-credential-file.cfg' will be sufficient.

When done, you will have something like this:

/path/to/dir
  |
  +- profiles/
  |    +- account1/
  |    |    +- aws-credential-file.cfg
  |    |    +- cert-XXXXX.pem
  |    |    +- pk-XXXXXXX.pem
  |    |
  |    +- account2/
  |    |    +- aws-credential-file.cfg
  |    |    +- cert-YYYYY.pem
  |    |    +- pk-YYYYYYY.pem
  ...

Using

$ awsenv_ls                 # list all profiles.
$ awsenv_set account1       # activate 'account1' as PROFILE_NAME, if it exists.

PS1 prompt

Try and add to your prompt:

export PS1="\u@h:\w $(__awsenv_ps1)\n\$ "

How it works

The following variables are manipulated:

AWS_ACCESS_KEY_ID           # aws: all API's
AWS_SECRET_ACCESS_KEY       # aws: all API's
AWS_CREDENTIAL_FILE         # aws: for IAM.
EC2_CERT                    # aws: for EC2 ami-tools
EC2_PRIVATE_KEY             # aws: for EC2 ami-tools
AWSENV_PROFILE              # mine: your current dir profile

Resources

For an example of configuring all AWS command line API tools take a look at this gist.

License

License

Copyright (c) 2012-2013 Marcus Vinicius Ferreira

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Bitdeli Badge

About

awskeys - AWS API Keys environment variables, à la RVM

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages