Created
July 30, 2020 15:34
-
-
Save lanimall/93da537f692859bf3856993bb4b9ad80 to your computer and use it in GitHub Desktop.
Simple Linux/Mac function to easily generate an AWS MFA token for AWS CLI access
This file contains 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
#!/bin/sh | |
MFA_SERIAL="arn:aws:iam::ACCOUNT:USER" | |
AWS_PROFILE=PROFILE | |
function awstoken() { | |
output=$(aws sts get-session-token --profile $AWS_PROFILE --serial-number $MFA_SERIAL --token-code "$@"); | |
aws_access_key_id=$(echo $output | jq -r '.Credentials.AccessKeyId') | |
aws_secret_access_key_id=$(echo $output | jq -r '.Credentials.SecretAccessKey') | |
aws_session_token=$(echo $output | jq -r '.Credentials.SessionToken') | |
export AWS_ACCESS_KEY_ID=$aws_access_key_id | |
export AWS_SECRET_ACCESS_KEY=$aws_secret_access_key_id | |
export AWS_SESSION_TOKEN=$aws_session_token | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment