Skip to content

Instantly share code, notes, and snippets.

@andreabedini
Created February 5, 2023 02:32
Show Gist options
  • Save andreabedini/ea3b3b8f3dcb1c7fc4f8450b4f5dbdec to your computer and use it in GitHub Desktop.
Save andreabedini/ea3b3b8f3dcb1c7fc4f8450b4f5dbdec to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
SESSION_NAME="$USER@$HOST" # or whatever
echo "Requesting federation token"
TOKEN1=$(aws sts get-federation-token --name "$SESSION_NAME" --policy-arns arn=arn:aws:iam::aws:policy/AdministratorAccess --output json)
URL1=$(jq -r '.Credentials | {sessionId:.AccessKeyId,sessionKey:.SecretAccessKey,sessionToken:.SessionToken} | @uri "https://signin.aws.amazon.com/federation?Action=getSigninToken&SessionType=json&Session=\(.)"' <<< "$TOKEN1")
echo "Requesting login token"
TOKEN2=$(curl --silent $URL1)
URL2=$(jq -r '@uri "https://signin.aws.amazon.com/federation?Action=login&Destination=https://console.aws.amazon.com&SigninToken=\(.SigninToken)"' <<< "$TOKEN2")
echo "Click this: $URL2"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment