An aws-vault helper
If you are using aws-vault to manage several accounts with different roles then you probably are tired of always write aws-vault exec profile --- aws <something>
This simple script avoid the direct use of aws-vault exec and allows you to simply run awscli commands like aws s3 ls instead.
This script only works on top of aws-vault so you need first to get your copy of aws-vault installed and configured with all your AWS profiles working properly.
- Download a copy of this repository:
cd ${HOME}
git clone https://github.com/emanuelpsilva/awsswitch.git
- Install the script into some path folder (in this example we'll use /usr/local/bin)
cp ${HOME}/awsswitch/awsswitch.sh /usr/local/bin/
chmod +x /usr/local/bin/awsswitch.sh
Case you want remove some profiles from the menu list, edit awsswitch.sh file and add them to the IGNORE_PROFILES variable.
- Run the script for first configuration (follow directions)
awsswitch.sh
- Add an alias to your shell profile (in this example we'll use .zprofile)
printf "\n#alias to use awsswitch\nalias aws=awsswitch.sh\n" >> ${HOME}/.zprofile
Don't forget to restart your shell terminal to make the alias active
- Any time you need to change current AWS profile (account), just run:
aws
The choosed profile will stay active until you run again above command
- Any time you want to run some aws command, just run:
aws <your parameters here, i.e.: s3 ls>
- To run other tools wrapped by awsswitch.sh, just add -- and your command:
aws -- terraform import aws_iam_role.my-role my-role-arn
- Case you want use inside a script, because alias are not available, you need to use like this:
awsswitch.sh <your parameters i.e.: s3 ls>
Thanks @MASNathan for the kickstarter push in this great ideia :)