Giter VIP home page Giter VIP logo

aws-profile's Introduction

aws-profile

Make AWS CLI profile switch easy, while working with many accounts.


NB! aws-profile works only with Amazon AWSCLI (Python) package.

Java-based version is not supported (for now).

For more details, please refer to aws.amazon.com/cli

Note: script was tested only in Bash

Installation

Install AWS CLI Tools:

$ pip install awscli

Install aws-profile:

$ curl -sSL https://raw.github.com/jaymecd/aws-profile/master/install.sh | sh

Or via clone:

$ git clone https://github.com/jaymecd/aws-profile.git
$ cp aws-profile/aws-* /usr/local/bin

Update resource file

Add following lines to ~/.profile or ~/.bashrc file:

export PATH="/usr/local/bin:$PATH"

# Amazon AWS Service CLI
complete -C aws_completer aws
alias aws-profile="source aws-profile"
alias aws="aws-wrapper"

Note: alias for aws-profile is required for transparent work, otherwise its requires to call via source manually, cause there is now way to expose environment variables back to parent.

Setup config

Populate config ~/.aws/config with desired profiles (refer AWS manual):

[profile secret-project]
aws_access_key_id=SOME-ACCESS-KEY-1
aws_secret_access_key=SOME-SECRET-KEY-1
region=us-east-2

[profile test-user]
aws_access_key_id=SOME-ACCESS-KEY-2
aws_secret_access_key=SOME-SECRET-KEY-2
region=eu-west-1

Overview profile

To list profiles, run command without arguments:

$ aws-profile

Output explained:

AWS_DEFAULT_PROFILE  : default                   <-- Current profile
AWS_CONFIG_FILE      : /Users/nick/.aws/config   <-- Config file
AWS_DEFAULT_REGION   : ~                         <-- Default region, if set
AWS_DEFAULT_OUTPUT   : ~                         <-- Default output, if set

Configured profiles  : secret-project test-user  <-- Allowed profiles

Switch between profiles

To switch aws profile to secret-project, run command:

$ aws-profile secret-project

To reset back to default, run command:

$ aws-profile +

To switch aws profiles off, run command:

$ aws-profile -

Run AWS commands:

Since there is an alias for aws original call, nothing is changed, call it as usual:

$ aws ec2 describe-instances --output text

Which gives output like:

NB! Running AWS CLI Tools with secret-project profile.

274082975067	r-8bebfdc4	226008221399
… SOME OTHER DATA … 

P.S. console autocomplete still works like a charm. Try aws TABTAB

Bash PS1 prompt hint:

Update .profile or .bashrc with following code:

function __ps_aws() {
    [ $AWS_CONFIG_FILE ] && echo " (aws ${AWS_DEFAULT_PROFILE:-default})"
}

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

And it will looks something like that:

nick@domain:~ (aws secret-project) $ _

FIN

P.P.S Patches are welcome

aws-profile's People

Contributors

jaymecd avatar

Stargazers

 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  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

aws-profile's Issues

Latest macOS Monterey makes the tool completely unuseable

This is what you get when you run the command even though the config file contains the profile and nothing was changed.

$ aws-profile lab -bash: php: command not found -bash: php: command not found ERROR: profile [lab] could not be found in [/Users/xxxxx/.aws/config] file.

I believe the problem here is that Monterey totally removed and replaced Python libraries, and in turn, a lot of the paths expected by aws-profile also started to experience problems.

Extract aws credentials

Export AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY of given profile to have backward compatibility with Java-based cli and 3rd-part tools.

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.