awsprof

Quickly and easily switch between AWS profiles

Usage no npm install needed!

<script type="module">
  import awsprof from 'https://cdn.skypack.dev/awsprof';
</script>

README

aws-profile-manager

npm David CircleCI codecov Greenkeeper badge CII Best Practices

Quickly and easily switch between AWS profiles

Motivation

I wanted something similar to nvm or rvm to manage and set my AWS_PROFILE environment variouable based on the directory I'm in.

Overview

The first proof of concept uses a centralized JSON file to keep track of what profiles to use for which directories in .aws-profile-manager/config.json rather than relying on some sort of dot RC file per project.

Currently, this doesn't actually export any environment variables, as I'm still trying to figure out the best way to do that.

Important note: this profile manager doesn't modify your ~/.aws/credentials file, and only parses the aws creds file locally to present options to the user.

Usage

First thing, install it globally:

git -c advice.detachedHead=false clone https://github.com/geoffdutton/aws-profile-manager.git --quiet -b v1.0.0 --depth=1 ~/.awsprof
cd ~/.awsprof && npm install

Then add this to .bash_profile:

export AWSPROF_INSTALL_DIR="$HOME/.awsprof"
[[ -f "$AWSPROF_INSTALL_DIR/awsprof.sh" ]] && \. "$AWSPROF_INSTALL_DIR/awsprof.sh"

And open a new terminal.

Then move to your project directory and save a profile:

$ cd ~/Projects/my-awesome-project
$ awsprof use
No profile set for ~/Projects/my-awesome-project
Chose a profile to use:
1)  default
2)  myStartup

Now you can see the export command to run when you're in that project directory:

$ cd ~/Projects/my-awesome-project
$ awsprof use
AWS_PROFILE=default

You can verify it exported the AWS_PROFILE environment variable:

$ awsprof
Current Env
AWS_PROFILE=default

Finally, you can reset it to be prompted again:

$ cd ~/Projects/my-awesome-project
$ awsprof reset
Removed stored profile for ~/Projects/my-awesome-project