A simple bash script/command for managing AWS environment credentials.
- Lists all defined AWS named profiles
- Checks the named profile currently in use
- Sets AWS credentials environment variables based on selected named profile
- Sets the following environment variables:
AWS_PROFILEAWS_DEFAULT_PROFILEAWS_REGIONAWS_DEFAULT_REGIONAWS_ACCESS_KEY_IDAWS_SECRET_ACCESS_KEY
- Linux or Mac OS
- Install AWS Cli
You can download the awsenv script to the a /bin directory of your choice. For example: /usr/local/bin
AWSENV_PATH=/usr/local/bin/awsenv
curl -o $AWSENV_PATH https://raw.githubusercontent.com/linsight/awsenv/main/awsenv
chmod +x $AWSENV_PATH
echo 'awsenv() { eval "$('$AWSENV_PATH' $@)" }' >> ~/.zshrc
awsenv: Shows the current profile/environment
awsenv ls: Lists all the defined profile names
awsenv use <profile_name>: sets all AWS credentials environment variables for given named profile;
-
awsenvmanages AWS credentials environment variables in your current shell session. This means that if you start a new terminal, the new terminal is likely to have no AWS credentials environment or a different AWS credentials environment from the one you are working on. To avoid confusion. It is recommended toAWS_ACCESS_KEY_IDandAWS_SECRET_ACCESS_KEYenvironment variables from your start-up script (e.g.~/.zshrc). You can keep theAWS_PROFILEandAWS_REGION. When you runawsenv, it will create theAWS_ACCESS_KEY_IDandAWS_SECRET_ACCESS_KEYenvironment variables for your current shell session based on theAWS_PROFILE. IfAWS_PROFILEis not available, you will be asked to runawsenv use <profile>. -
Once
awsenvsets the AWS credentials environment for you. You don't need to append--profileoption to the AWS CLI commands anymore. The AWS CLI will use the profile set with theAWS_PROFILEvariable. -
Feel free to enhance the script for other variables like
AWS_SESSION_TOKEN