Skip to content

Instantly share code, notes, and snippets.

@larsyencken
Created June 5, 2014 04:23
Show Gist options
  • Save larsyencken/e44763a9721d10eea0e0 to your computer and use it in GitHub Desktop.
Save larsyencken/e44763a9721d10eea0e0 to your computer and use it in GitHub Desktop.
Switch between AWS accounts
#!/bin/bash
#
# aws_profile
#
# Manages multiple AWS accounts through symlinks.
#
if [ ! -d ~/.aws ]; then
echo "ERROR: can't find \${HOME}/.aws directory" 1>&2
exit 1
fi
cd ~/.aws
function report_current()
{
current=$(ls -la current | sed 's/^.*-> //g')
if [ -z "${current}" ]; then
echo none
else
echo ${current}
fi
}
function switch_current()
{
target="$1"
if [ -d "${target}" ]; then
rm -f current
ln -s "${target}" current
echo "Switched to ${target}"
else
echo "Profile ${target} not found (or not mounted)"
fi
}
function usage()
{
echo "Usage: aws_profile [profile]" 1>&2
exit 1
}
if [ $# -eq 0 ]; then
report_current
elif [ $# -eq 1 ]; then
switch_current "$1"
else
usage
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment