Git Product home page Git Product logo

awsp's Introduction

AWSP - AWS Profile Switcher

Easily switch between AWS Profiles

Prereqs

Setup your profiles using the aws cli

aws configure --profile PROFILE_NAME

You can also leave out the --profile PROFILE_NAME param to set your default credentials

Refer to this doc for more information https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-getting-started.html

Setup

npm install -g awsp

Add the following to your .bashrc or .zshrc config

alias awsp="source _awsp"

Usage

awsp

Show your AWS Profile in your shell prompt

For better visibility into what your shell is set to it's helpful to configure your prompt to show the value of the env variable AWS_PROFILE.

Here's a sample of my zsh prompt config using oh-my-zsh themes

function aws_prof {
  local profile="${AWS_PROFILE:=default}"

  echo "%{$fg_bold[blue]%}aws:(%{$fg[yellow]%}${profile}%{$fg_bold[blue]%})%{$reset_color%} "
}
PROMPT='OTHER_PROMPT_STUFF $(aws_prof)'

awsp's People

Contributors

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

awsp's Issues

Use $AWS_CONFIG_FILE if default $HOME/.aws/config doesn't exist

This assumes the config file exists in the default location of $HOME/.aws/config

It should check if the env var $AWS_CONFIG_FILE is set and to use this location.

const homeDir = process.env['HOME']

% echo $AWS_CONFIG_FILE
/Users/my-user/custom/path/to/config
% awsp
AWS Profile Switcher
Error: [Error: ENOENT: no such file or directory, open '/Users/my-user/.aws/config'] {
  errno: -2,
  code: 'ENOENT',
  syscall: 'open',
  path: '/Users/my-user/.aws/config'
}


Windows support - install issue?

Is this supported Windows 10?

I am getting this issue when I run the install:
image

I checked the debug log and not much of a clue in there.
Many thanks

Crashes Terminal With Ubuntu

How is this supposed to work? Running the awsp shows me my profile options, but crashes terminal when I select an option.

Looks like writeToConfig has been called my profile choice is in file ~/.awsp.

However when I echo $AWS_PROFILE this is empty.

My setup is:
OS: Ubuntu 18.04.4 LTS
Node: 10.16.3

Support Fish Shell

After npm i -g awsp, I added the line alias awsp=(source <_awsp-path>/_awsp) and sourced the config file via source <config-path>/config.fish. Which resulted in the following error:

_awsp (line 5): Unsupported use of '='. In fish, please use 'set selected_profile "$(cat ~/.awsp)"'.

[FEATURE] Write active profile credentials to .aws/credentials as default profile

Firstly, this is an awesome tool, thank you for creating it!

Some functionality I would love to see is when a profile is selected, get-role-credentials is run and the temporary credentials are written to ./aws/credentials as the "default" profile.

Currently, the workflow for devs that work with boto3 or any aws JDK is that we have to go to the aws sso sign in console, generate temporary credentials, copy them, and paste them into .aws/credentials under the default profile.

If we want to switch profiles, we have to repeat this process.

botocore.exceptions.ProfileNotFound occured on AWS CLI after choose the default profile.

If the default profile is selected, is it not necessary to unset AWS_PROFILE from environment variable?

$ aws configure list
      Name                    Value             Type    Location
      ----                    -----             ----    --------
   profile                <not set>             None    None
access_key     ****************XXXX shared-credentials-file
secret_key     ****************XXXX shared-credentials-file
    region           ap-northeast-1      config-file    ~/.aws/config

$ awsp
AWS Profile Switcher
? Choose a profile default

$ aws configure list
Traceback (most recent call last):
  File "/Users/*****/.pyenv/versions/2.7.14/bin/aws", line 27, in <module>
    sys.exit(main())
  File "/Users/*****/.pyenv/versions/2.7.14/bin/aws", line 23, in main
    return awscli.clidriver.main()
  File "/Users/*****/.pyenv/versions/2.7.14/lib/python2.7/site-packages/awscli/clidriver.py", line 59, in main
    rc = driver.main()
  File "/Users/*****/.pyenv/versions/2.7.14/lib/python2.7/site-packages/awscli/clidriver.py", line 193, in main
    command_table = self._get_command_table()
  File "/Users/*****/.pyenv/versions/2.7.14/lib/python2.7/site-packages/awscli/clidriver.py", line 102, in _get_command_table
    self._command_table = self._build_command_table()
  File "/Users/*****/.pyenv/versions/2.7.14/lib/python2.7/site-packages/awscli/clidriver.py", line 122, in _build_command_table
    command_object=self)
  File "/Users/*****/.pyenv/versions/2.7.14/lib/python2.7/site-packages/botocore/session.py", line 725, in emit
    return self._events.emit(event_name, **kwargs)
  File "/Users/*****/.pyenv/versions/2.7.14/lib/python2.7/site-packages/botocore/hooks.py", line 356, in emit
    return self._emitter.emit(aliased_event_name, **kwargs)
  File "/Users/*****/.pyenv/versions/2.7.14/lib/python2.7/site-packages/botocore/hooks.py", line 228, in emit
    return self._emit(event_name, kwargs)
  File "/Users/*****/.pyenv/versions/2.7.14/lib/python2.7/site-packages/botocore/hooks.py", line 211, in _emit
    response = handler(**kwargs)
  File "/Users/*****/.pyenv/versions/2.7.14/lib/python2.7/site-packages/awscli/customizations/preview.py", line 69, in mark_as_preview
    service_name=original_command.service_model.service_name,
  File "/Users/*****/.pyenv/versions/2.7.14/lib/python2.7/site-packages/awscli/clidriver.py", line 314, in service_model
    return self._get_service_model()
  File "/Users/*****/.pyenv/versions/2.7.14/lib/python2.7/site-packages/awscli/clidriver.py", line 331, in _get_service_model
    api_version = self.session.get_config_variable('api_versions').get(
  File "/Users/*****/.pyenv/versions/2.7.14/lib/python2.7/site-packages/botocore/session.py", line 284, in get_config_variable
    elif self._found_in_config_file(methods, var_config):
  File "/Users/*****/.pyenv/versions/2.7.14/lib/python2.7/site-packages/botocore/session.py", line 311, in _found_in_config_file
    return var_config[0] in self.get_scoped_config()
  File "/Users/*****/.pyenv/versions/2.7.14/lib/python2.7/site-packages/botocore/session.py", line 388, in get_scoped_config
    raise ProfileNotFound(profile=profile_name)
botocore.exceptions.ProfileNotFound: The config profile () could not be found

$ unset AWS_PROFILE

$ aws configure list
      Name                    Value             Type    Location
      ----                    -----             ----    --------
   profile                <not set>             None    None
access_key     ****************XXXX shared-credentials-file
secret_key     ****************XXXX shared-credentials-file
    region           ap-northeast-1      config-file    ~/.aws/config

Suggestion of a new functionallity

The awsp helps me to save time changing the profiles every day and I thanks for that. I would like to see the option to change the profile directly only typing the profile name (awsp ), not only using the selector.

ZSH Issue

Updated: Issue has been fixed.

I have AWS CLI installed, ZSH, Iterm2. After running:

awsp

Getting following error:

AWS Profile Switcher
No profiles found.
Refer to this guide for help on setting up a new AWS profile:
https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-getting-started.html
Error: TypeError: Cannot read property 'profile' of undefined
    at writeToConfig (/usr/local/lib/node_modules/awsp/index.js:57:17)
cat: /Users/***/.awsp: No such file or directory

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.