Skip to content

Instantly share code, notes, and snippets.

@EntropyWorks
Last active January 10, 2018 11:49
Show Gist options
  • Save EntropyWorks/5d529cc96cffaa37df3d68ec0edceeed to your computer and use it in GitHub Desktop.
Save EntropyWorks/5d529cc96cffaa37df3d68ec0edceeed to your computer and use it in GitHub Desktop.
Do you have multiple AWS profiles that you need to swap between?
#!/bin/bash
#
# Do you have multiple AWS profiles?
# Here is how I deal with them.
#
# Make sure you add "${HOME}/.bash_aws_profile" to your .bashrc or .bash_profile so
# all new terminal sessions are updated with your choice.
#
aws-swap(){
unset AWS_DEFAULT_PROFILE
PS3="Your choice: "
while [[ $AWS_DEFAULT_PROFILE = "" ]]; do
echo "Please enter the number the AWS profile you want"
select AWS_DEFAULT_PROFILE in $(grep "^\[profile" ~/.aws/config | awk '{print $2}' | tr -d ']'); do
if [[ $AWS_DEFAULT_PROFILE = "" ]]; then
echo "Please enter a valid number. Retry."
else
export AWS_DEFAULT_PROFILE="$AWS_DEFAULT_PROFILE"
export AWS_PROFILE="$AWS_DEFAULT_PROFILE"
echo "export AWS_DEFAULT_PROFILE=$AWS_DEFAULT_PROFILE" > "${HOME}/.bash_aws_profile"
echo "export AWS_PROFILE=$AWS_DEFAULT_PROFILE" >> "${HOME}/.bash_aws_profile"
fi
break
done
done
# env | grep AWS_* | printf " $1"
}
aws-swap
# Copyright (c) 2017 Yazz Atlas.
# All rights reserved.
#
# Redistribution and use in source and binary forms are permitted
# provided that the above copyright notice and this paragraph are
# duplicated in all such forms and that any documentation,
# advertising materials, and other materials related to such
# distribution and use acknowledge that the software was developed
# by the Entropy Works Inc. The name of Entropy Works Inc.
# may not be used to endorse or promote products derived
# from this software without specific prior written permission.
# THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
# IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment