All Projects → vaulstein → awsprofile

vaulstein / awsprofile

Licence: other
Shell script to ease management of AWS profiles

Programming Languages

shell
77523 projects

Projects that are alternatives of or similar to awsprofile

aws-export-profile
Export AWS profiles to your shell environment
Stars: ✭ 45 (+275%)
Mutual labels:  aws-cli, aws-profile
aws-export-assume-profile
Export AWS profiles to your shell environment
Stars: ✭ 40 (+233.33%)
Mutual labels:  aws-cli, aws-profile
dotfiles
No description or website provided.
Stars: ✭ 16 (+33.33%)
Mutual labels:  zshrc
dotfiles
Dotfiles
Stars: ✭ 25 (+108.33%)
Mutual labels:  zshrc
mlflow-tracking-server
MLFLow Tracking Server based on Docker and AWS S3
Stars: ✭ 59 (+391.67%)
Mutual labels:  aws-cli
dotfiles
my personal dotfiles managed by dotbot, zinit
Stars: ✭ 65 (+441.67%)
Mutual labels:  zshrc
anyrc
🐚 Bring your shell environment to anywhere
Stars: ✭ 28 (+133.33%)
Mutual labels:  zshrc
aws-kinesis-consumer
Consume an AWS Kinesis Data Stream to look over the records from a terminal.
Stars: ✭ 23 (+91.67%)
Mutual labels:  aws-cli
iterm-oh-my-zsh-powerlevel10k
Improved Terminal Experience with Oh My Zsh, iTerm2, PowerLevel10K
Stars: ✭ 24 (+100%)
Mutual labels:  zshrc
docker-files
Teracy docker-files project to build common Docker images
Stars: ✭ 87 (+625%)
Mutual labels:  aws-cli
configuration
Config files
Stars: ✭ 12 (+0%)
Mutual labels:  zshrc
aws-missing-tools
Random tools I've written to make life easier using AWS, namely aws-choose-profile and aws-mfa-login
Stars: ✭ 46 (+283.33%)
Mutual labels:  aws-cli
Dotfiles
🍙 Personal dotfiles repository.
Stars: ✭ 148 (+1133.33%)
Mutual labels:  zshrc
plasma-dotfiles
In this repository I intend to keep configuration files that I deem important, in addition to the theme customizations that I make to have a consistent working environment.
Stars: ✭ 58 (+383.33%)
Mutual labels:  zshrc
zsh-launchpad
🚀 Simple, educational dotfiles template to get started with Zsh and learn about its features
Stars: ✭ 141 (+1075%)
Mutual labels:  zshrc
aws-sso-creds-helper
A command line util for using SSO credentials with AWS SDK on AWS CLI v2 until native support is released
Stars: ✭ 34 (+183.33%)
Mutual labels:  aws-cli
awslogin
Login to the AWS management console.
Stars: ✭ 17 (+41.67%)
Mutual labels:  aws-cli
zcomet
zcomet - Fast, Simple Zsh Plugin Manager
Stars: ✭ 144 (+1100%)
Mutual labels:  zshrc
s3cli
Command line tool for S3
Stars: ✭ 21 (+75%)
Mutual labels:  aws-cli
docker-dind-awscli
A Docker image for Docker-in-Docker (dind) with AWS CLI v2 awscli tool included
Stars: ✭ 36 (+200%)
Mutual labels:  aws-cli

AWS PROFILE

INTRODUCTION

Managing multiple AWS accounts from aws-cli tends to be a little tedious. When you need to switch between multiple AWS accounts, it seems to be a hassle keeping a track of the current account, all the available account names.

Even setting the variable and using it to switch between accounts doesn't seem like the right deal.

export AWS_PROFILE=user2

Aliases can be used to manage AWS profiles in a better way.

With aliases we can do the following:

  • List available profiles
  • View current profile configuration
  • Switch to another profile

Creating Aliases

First we will create functions that would be invoked by our Alias

Create a file as below:

 vim ~/.awsAliases

Next add the below lines in the file:

#!/bin/bash
function _awsListAll() {

    credentialFileLocation=${AWS_SHARED_CREDENTIALS_FILE};
    if [ -z $credentialFileLocation ]; then
        credentialFileLocation=~/.aws/credentials
    fi
 
    while read line; do
        if [[ $line == "["* ]]; then echo "$line"; fi;
    done < $credentialFileLocation;
};
 
function _awsSwitchProfile() {
   if [ -z $1 ]; then  echo "Usage: awsp profilename"; return; fi
   
   exists="$(aws configure get aws_access_key_id --profile $1)"
   if [[ -n $exists ]]; then
       export AWS_DEFAULT_PROFILE=$1;
       export AWS_PROFILE=$1;
       export AWS_REGION=$(aws configure get region --profile $1);
       echo "Switched to AWS Profile: $1";
       aws configure list
   fi
};

Now if you are using bash, open bash_profile as below:

vim ~/.bash_profile

And add the following files:

. ~/.awsAliases
alias awsall="_awsListAll"
alias awsp="_awsSwitchProfile"
alias awswho="aws configure list"

If you are using zshrc, then add the lines in ~/.zshrc

Now, reload your bash profile or zshrc as below

source ~/.bash_profile # For zshrc source ~/.zshrc

Running Aliases

To list all the profiles use:

awsall

To switch between profiles use:

awsp <profileName>

To show current profile details:

awswho

Credits

Code based on article written by Carl Nordenflet

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].