Last active
January 20, 2022 15:30
-
-
Save reschenburgIDBS/e45c6350fca7cbed082c47e1e352d385 to your computer and use it in GitHub Desktop.
quick aws assume-role based on configured profiles - requires https://github.com/junegunn/fzf and https://stedolan.github.io/jq/
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
function awsaroff { | |
unset AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY AWS_SESSION_TOKEN | |
aws sts get-caller-identity | |
} | |
function awsar { | |
unset AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY AWS_SESSION_TOKEN | |
local ARN="$(cat ~/.aws/config | grep "arn:aws" | awk -F " = " '{print $2};' | fzf)" | |
echo "assuming role: ${ARN}" | |
if [[ ! $1 ]]; then | |
local SESSIONNAME="$(whoami)" | |
else | |
local SESSIONNAME=$1 | |
fi | |
TEMPSESSION="$(aws sts assume-role --role-arn "$ARN" --role-session-name "$SESSIONNAME")" | |
export AWS_ACCESS_KEY_ID="$(echo $TEMPSESSION | jq -r .Credentials.AccessKeyId)" | |
export AWS_SECRET_ACCESS_KEY="$(echo $TEMPSESSION | jq -r .Credentials.SecretAccessKey)" | |
export AWS_SESSION_TOKEN="$(echo $TEMPSESSION | jq -r .Credentials.SessionToken)" | |
aws sts get-caller-identity | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment