Coder Social home page Coder Social logo

aws-account-switcher's Introduction

AWS Account Switcher

### WARNING ###
Make a backup of your .aws/credentials folder before using this utility!
Also the default rotation time is 30 days!

Repository to allow you to switch to various AWS Accounts, rotate your access keys and assume roles on the command line without the need of exporting those pesky bash env vars!

Components

  • switcher.py
  • profiles.json

What to do?

  1. Create a profiles.json in the project for yourself (copy/rename the profiles_example.json)
  2. Update the values for the accounts you wish to switch to (home, work, nonprod, prod etc.)
  3. Run using python3 switcher.py

Why?

This script was written to enable read only users to assume a role to run cli commands that they normally wouldn't have permissions to do. The script since then has developed into a auto key rotator and account switcher. This was initially written by myself for the developers where I work, it was suggested that I open source it because 'it's a nightmare switching accounts/roles manually!'.

profiles.json example

{
  "profiles": [
    {
      "type": "personal",
      "role": "role",
      "account_number": "0011223344",
      "username": "[email protected]",
      "aws_access_key_id": "PERSONALACCESSKEY",
      "aws_secret_access_key": "PERSONALSECRETACCESSKEY",
      "mfa": "arn:aws:iam::0011223344:mfa/[email protected]",
      "duration": ""
    },
    {
      "type": "work",
      "role": "role",
      "account_number": "0011223355",
      "username": "[email protected]",
      "aws_access_key_id": "WORKACCESSKEY",
      "aws_secret_access_key": "WORKSECRETACCESSKEY",
      "mfa": "arn:aws:iam::0011223355:mfa/[email protected]",
      "duration": ""
    }
  ]
}

aws-account-switcher's People

Contributors

joshcarter-ops avatar

Stargazers

Douglas Alderman avatar Alex Le Peltier avatar

Watchers

Alex Le Peltier avatar  avatar

aws-account-switcher's Issues

When running script with 2 access keys set profile.json is cleared

I think this might be a niche bug but if I have two access keys set and run the script it throws a "Cannot exceed quota for AccessKeysPerUser: 2" error but then removes the contents of profiles.json. I think it might be a good idea to check for the key quota before running any code. I'm happy to create an MR to solve this issue.

Here is the error:

An error occurred (LimitExceeded) when calling the CreateAccessKey operation: Cannot exceed quota for AccessKeysPerUser: 2 Traceback (most recent call last): File "switcher.py", line 150, in <module> rotate_keys() File "switcher.py", line 94, in rotate_keys new_key = json.loads(bash('aws iam create-access-key --user-name {}'.format(username)))['AccessKey'] File "/usr/lib/python3.6/json/__init__.py", line 354, in loads return _default_decoder.decode(s) File "/usr/lib/python3.6/json/decoder.py", line 339, in decode obj, end = self.raw_decode(s, idx=_w(s, 0).end()) File "/usr/lib/python3.6/json/decoder.py", line 357, in raw_decode raise JSONDecodeError("Expecting value", s, err.value) from None json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

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.