Created
June 5, 2014 04:23
-
-
Save larsyencken/e44763a9721d10eea0e0 to your computer and use it in GitHub Desktop.
Switch between AWS accounts
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
#!/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