Skip to content

Instantly share code, notes, and snippets.

@nijave
Last active January 29, 2020 19:15
Show Gist options
  • Save nijave/e73076ad9d80d4b96c6f041630e09a81 to your computer and use it in GitHub Desktop.
Save nijave/e73076ad9d80d4b96c6f041630e09a81 to your computer and use it in GitHub Desktop.
Sets up aws-login alias
if [[ ! -d ~/code/aws-login-windows ]]; then
mkdir -p ~/code/aws-login-windows
git clone https://github.com/Root-App/aws-login-windows.git ~/code/aws-login-windows
fi
pushd ~/code/aws-login-windows
git pull
popd
if [[ "$ZSH_NAME" != "" ]]; then
PROFILE_FILE=~/.zprofile
else
PROFILE_FILE=~/.my_profile
fi
type aws-login || cat <<EOF >> $PROFILE_FILE
aws-login() {
if [[ "\$1" = "list" ]]; then
AWS_CONFIG_FILE=~/code/aws-login-windows/.aws/config aws-okta list
return
fi
AWS_CONFIG_FILE=~/code/aws-login-windows/.aws/config aws-okta env --assume-role-ttl=12h --session-ttl=12h $1
if [[ \$? -eq 0 ]]; then
eval \$(AWS_CONFIG_FILE=~/code/aws-login-windows/.aws/config aws-okta env --assume-role-ttl=12h --session-ttl=12h $1)
export ROOT_AWS_DEFAULT_ROLE_SESSION_DURATION=3600
echo ""
echo "Successfully exported the above variables and logged in as $1"
fi
}
aws-logout() {
unset AWS_SESSION_TOKEN
unset AWS_OKTA_PROFILE
unset AWS_OKTA_ASSUMED_ROLE
unset AWS_DEFAULT_REGION
unset AWS_SECRET_ACCESS_KEY
unset AWS_REGION
unset AWS_OKTA_ASSUMED_ROLE_ARN
unset AWS_ACCESS_KEY_ID
unset AWS_SECURITY_TOKEN
unset ROOT_AWS_DEFAULT_ROLE_SESSION_DURATION
}
EOF
. $PROFILE_FILE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment