Skip to content

Instantly share code, notes, and snippets.

@ben-bourdin451
Created July 2, 2018 13:20
Show Gist options
  • Save ben-bourdin451/b4894438d4d4de8012f3c7ab5b75d8a8 to your computer and use it in GitHub Desktop.
Save ben-bourdin451/b4894438d4d4de8012f3c7ab5b75d8a8 to your computer and use it in GitHub Desktop.
Bash script to refresh session tokens for assuming roles that require MFA
#!/bin/bash
read -p 'MFA Token: ' mfavar
line=$(aws sts get-session-token --profile $AWS_IDENTITY_ACCOUNT --serial-number $MFA_SERIAL --token-code $mfavar --output text)
echo $line | awk 'BEGIN {FS=" "}; {printf("[default]\naws_access_key_id=%s\naws_secret_access_key=%s\naws_session_token=%s\n#expiry %s",$2,$4,$5,$3)}' > ~/.aws/credentials
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment