Skip to content

Instantly share code, notes, and snippets.

@lanimall
Created July 30, 2020 15:34
Show Gist options
  • Save lanimall/93da537f692859bf3856993bb4b9ad80 to your computer and use it in GitHub Desktop.
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
#!/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