Giter Site home page Giter Site logo

awsp's Introduction

AWS credential profile changer

Excerpt from IAM Best Practices:

Delegate by using roles instead of by sharing credentials

You might need to allow users from another AWS account to access resources in your AWS account. If so, don't share security credentials, such as access keys, between accounts. Instead, use IAM roles. You can define a role that specifies what permissions the IAM users in the other account are allowed, and from which AWS accounts the IAM users are allowed to assume the role.

To make process of switching profiles (environment variables AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY among others) it is handy to use the code provided on this repo.

Features

  • Autocomplete of available profiles (awsp + tab + tab)
  • Support configurable location of credentials file (AWS_SHARED_CREDENTIALS_FILE environment variable)
  • Full compatibility with official AWS CLI
  • Assume roles which require MFA
  • What else you can think of? Please open an issue or submit PR.

Install

  • jq should be installed
  • Download awsp_functions.sh anywhere you like (for example, ~/awsp_functions.sh) and make it executable:
    $ wget -O ~/awsp_functions.sh https://raw.githubusercontent.com/antonbabenko/awsp/master/awsp_functions.sh
    $ chmod +x ~/awsp_functions.sh
  • Depending on which version of shell you use, edit ~/.bash_profile or similar to include: source ~/awsp_functions.sh
  • (Optional) Enable aliases and auto-completion into your ~/.bash_profile or similar:
    alias awsall="_awsListAll"
    alias awsp="_awsSwitchProfile"
    alias awswho="aws configure list"

    complete -W "$(cat $HOME/.aws/credentials | grep -Eo '\[.*\]' | tr -d '[]')" _awsSwitchProfile

Examples

Content of ~/.aws/credentials:

[company-anton]
aws_access_key_id=EXAMPLEACCESSKEY
aws_secret_access_key=EXAMPLESECRETACCESSKEY

[company-staging-anton]
role_arn=arn:aws:iam::222222222222:role/company-staging
source_profile=company-anton

[company-production-anton]
role_arn=arn:aws:iam::111111111111:role/company-production
source_profile=company-anton
mfa_serial=arn:aws:iam::333333333333:mfa/anton

To change AWS profile to use staging account (222222222222):

$ awsp company-staging-anton

To change AWS profile to use production account (111111111111) which requires MFA token created in IAM account (333333333333, company-anton):

$ awsp company-production-anton
# Please enter your MFA token for arn:aws:iam::333333333333:mfa/anton
> 123456

Note

This code has been tested only on Mac and there are no intentions to make it to work on other systems (if necessary), but PR are very much welcome!

Authors

Created by Anton Babenko with inspiration from several code snippets

License

Apache 2 Licensed. See LICENSE for full details.

awsp's People

Contributors

antonbabenko avatar robpickerill 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.