Created
April 17, 2020 07:16
-
-
Save SodaDev/115d05d3a894aef8b252f2edc038d39f to your computer and use it in GitHub Desktop.
AWS configure sso login
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 aws-sso() { | |
aws configure sso --profile default | |
ACCESS_KEY_POSTFIX="\"$(aws configure list --profile default | grep access_key | awk '{print $2}' | sed 's/*//g')\"" | |
SECRET_KEY_POSTFIX="$(aws configure list --profile default | grep secret_key | awk '{print $2}' | sed 's/*//g')" | |
ACCESS_KEY_FILTER=". | select(.Credentials.AccessKeyId | endswith($ACCESS_KEY_POSTFIX))" | |
SECRET_KEY_FILTER=". | select(.Credentials.SecretAccessKey | endswith(\"$SECRET_KEY_POSTFIX\"))" | |
for entry in ~/.aws/cli/cache/* | |
do | |
FOUND_ACCESS_KEY="$(cat $entry | jq -r "$ACCESS_KEY_FILTER")" | |
FOUND_ACCESS_SECRET="$(cat $entry | jq -r "$SECRET_KEY_FILTER")" | |
if [[ ("$FOUND_ACCESS_KEY" != "") && ("$FOUND_ACCESS_SECRET" != "")]]; then | |
AWS_CREDENTIALS=$(cat <<-END | |
[default] | |
aws_access_key_id = $(cat $entry | jq -r .Credentials.AccessKeyId) | |
aws_secret_access_key = $(cat $entry | jq -r .Credentials.SecretAccessKey) | |
aws_session_token = $(cat $entry | jq -r .Credentials.SessionToken) | |
END | |
) | |
echo -e "FOUND credentials \n$AWS_CREDENTIALS" | |
echo "${AWS_CREDENTIALS[*]}" > ~/.aws/credentials | |
break | |
fi | |
done | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment