Skip to content

Instantly share code, notes, and snippets.

@thomashartm
Last active May 26, 2023 02:51
Show Gist options
  • Save thomashartm/4b1ba2c36bc88e523c9933c4b0256b2c to your computer and use it in GitHub Desktop.
Save thomashartm/4b1ba2c36bc88e523c9933c4b0256b2c to your computer and use it in GitHub Desktop.
Easy AWS profile switch via bash script.
#!/bin/bash
#
# 1. Place this script somewhere in your path:
# touch /Users/username/path-to-your-scripts-directory/awsprofile.sh
# 2. Save this script and make it executable
# chmod +x /Users/username/path-to-your-scripts-directory/awsprofile.sh
# 3. Add the directory to your bash profile
# export PATH="/path-to-your-scripts-directory:$PATH"
# 4. Source your bash profile
# awsprofile.sh
show_profiles() {
echo -e "Prepare dev environment settings."
echo -e "Usage:"
echo -e "\tawsenv <environment>"
echo -e ""
echo -e "Available environments:"
echo -e ""
list="$(aws configure list-profiles)"
while IFS= read -r line; do
echo -e "\t$line"
done <<< "$list"
echo -e ""
echo -e "Current config:"
echo -e ""
config="$(aws configure list)"
echo -e "\t$config"
exit 1
}
if [ $# -eq 1 ]; then
echo -e "Setting AWS profile to $1"
export AWS_PROFILE="$1"
else
show_profiles
exit 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment