Skip to content

Instantly share code, notes, and snippets.

@cmerrick
Created May 17, 2015 19:06
Show Gist options
  • Save cmerrick/5977824f3375e12b7223 to your computer and use it in GitHub Desktop.
Save cmerrick/5977824f3375e12b7223 to your computer and use it in GitHub Desktop.
Helper functions for installing AWS Role temporary keys into your environment
aws-reset ()
{
unset AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY \
AWS_SECURITY_TOKEN AWS_SESSION_TOKEN \
AWS_ROLE_NAME AWS_ROLE_EXPIRATION
source "/etc/profile.d/aws-env.sh"
}
assume-role ()
{
aws-reset
AWS_ROLE_TMPFILE="$HOME/.aws-role-tmp"
TOKEN_BIN=$(which get-role-token)
echo -n "Role name: "
read ROLE
echo -n "MFA Token: "
read TOKEN
echo -n "Acquiring Token..."
$TOKEN_BIN $ROLE $TOKEN > $AWS_ROLE_TMPFILE
if [ $? -eq 0 ] && [ -s $AWS_ROLE_TMPFILE ]; then
source $AWS_ROLE_TMPFILE
echo " Installed!"
else
echo " Failed"
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment