Skip to content

Instantly share code, notes, and snippets.

@jerm
Last active December 26, 2015 04:39
Show Gist options
  • Save jerm/7095159 to your computer and use it in GitHub Desktop.
Save jerm/7095159 to your computer and use it in GitHub Desktop.
Bash function to easily (re)point boto and awscli to your preferred config files
# @jermops 's boto and aws cli config unifyer/switcher
cb(){
set_default_boto(){
unset BOTO_CONFIG
unset BOTO_DISPLAYENV
export AWS_CONFIG_FILE=~/.boto
echo "Using default .boto"
}
#Change boto env
unset found
BOTO_SEARCHENV=$1
if [ -n "$BOTO_SEARCHENV" ]; then
BOTO_SUFFIX="-$BOTO_SEARCHENV"
else
#Using default .boto... hopefully it exists"
set_default_boto
return 0
fi
# I one point ran into a scanario where it made sense to have .boto files
# within project folders... maybe it was before i made this script. At any
# rate, we support .boto files within the current folder and your $HOME
# folder, in that order.
for path in `pwd` $HOME
do
if [ -e "$path/.boto$BOTO_SUFFIX" ]; then
export BOTO_DISPLAYENV=${BOTO_SEARCHENV:-default}
export BOTO_CONFIG=$path/.boto$BOTO_SUFFIX
export AWS_CONFIG_FILE=$path/.boto$BOTO_SUFFIX
echo "Using $path/.boto$BOTO_SUFFIX"
found=1
break
fi
done
if [ -z "$found" ]; then
echo "#WARN: .boto$BOTO_SUFFIX not found. Not changing anything"
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment