Last active
February 18, 2022 09:16
-
-
Save NimaSaed/8d8989e6e662359ba7c3a20e42e2a419 to your computer and use it in GitHub Desktop.
Bash AWS Profile Changer
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Add this function to the end of your ~/.bashrc | |
function aws_profile() { | |
local aws_home="$HOME/.aws" | |
local profiles=(`\ | |
cat ${aws_home}/config | \ | |
grep profile | \ | |
sed 's/\[//g;s/\]//g' | \ | |
cut -d " " -f 2`); | |
PS3="Select a profile: [none = 0] " | |
select profile in ${profiles[@]} | |
do | |
selected=$profile; | |
break; | |
done | |
unset $PS3; | |
if [ ! -z ${profile} ]; | |
then | |
export AWS_PROFILE="${profile}"; | |
export AWS_REGION=$(cat ${aws_home}/config | sed -n "/${profile}/,/\[/p" | grep region | cut -d '=' -f 2 | sed 's/ //g') | |
export AWS_ACCESS_KEY_ID=$(cat ${aws_home}/credentials | sed -n "/${profile}/,/\[/p" | grep aws_access_key_id | cut -d '=' -f 2 | sed 's/ //g') | |
export AWS_SECRET_ACCESS_KEY=$(cat ${aws_home}/credentials | sed -n "/${profile}/,/\[/p" | grep aws_secret_access_key | cut -d '=' -f 2 | sed 's/ //g') | |
else | |
AWS_PROFILE="" | |
AWS_REGION="" | |
AWS_ACCESS_KEY_ID="" | |
AWS_SECRET_ACCESS_KEY="" | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment