Giter Site home page Giter Site logo

awsenv's Introduction

awsenv

Python utility to manage AWS environment variables for multiple profiles, especially with cross-account access enabled.

Specifically, awsenv:

  • Determines a profile to use based on CLI input or the AWS_PROFILE environment variables
  • Loads AWS configuration from ~/.aws/config (or AWS_CONFIG_FILE) and ~/.aws/credentials
  • Invokes STS Assume Role if the profile defines a role_arn
  • Prints shell statements to (un)set appropriate environment variables

Build Status

Credits

awsenv is largely based on mlrobinson's assume_role.py script.

Installation

Use pip:

pip install awsenv

For virtualenvwrapper users, the following is recommended:

# create a new virtualenv
mkvirtual awsenv

# install with pip
pip install awsenv

# soft link the console script (assumes that ~/bin is in your $PATH)
ln -s ~/.virtualenvs/awsenv/bin/awsenv ~/bin

Command Line Usage

Invoke awsenv with a profile name (or no arguments for the default profile):

awsenv myprofile

Or set the AWS_PROFILE environment variable and run awsenv without arguments:

export AWS_PROFILE=myprofile
awsenv

Can also optionally override the region by setting the AWS_REGION environment variable.

The output will be a series of export (or unset) statements:

export AWS_DEFAULT_REGION=us-west-2
export AWS_SESSION_TOKEN=<redacted>
export AWS_PROFILE=myprofile
export AWS_SESSION_NAME=<redacted>
export AWS_SECRET_ACCESS_KEY=<redacted>
export AWS_ACCESS_KEY_ID=<redacted>

Evaluate the output of to load it into your shell:

eval "$(awsenv myprofile)"

Programmatic Usage

Python programs and scripts that use botocore and need cross-account access can use the underlying library directly to obtain an AWSProfile instance. The instance, in turn, defines its own create_client function, which will properly set the profile's region, access key, secret key, and session token:

from awsenv.main import get_profile

profile = get_profile()
client = profile.create_client("ec2")
print client.describe_instances()

Session Caching

awsenv will check its current environment for the AWS_SESSION_NAME, AWS_SESSION_TOKEN, and AWS_PROFILE variables; if these are defined and have a non-expired session, the existing session will be re-used.

awsenv's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.