Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save allenluce/7e2cb29167e0048088e5c552f7426db0 to your computer and use it in GitHub Desktop.
Save allenluce/7e2cb29167e0048088e5c552f7426db0 to your computer and use it in GitHub Desktop.
awsmfa () {
# Remove the old [default] section
sed -i.bak '/^\[default\]/,/# End of \[default\]/d' ~/.aws/credentials
# Get new token && append to credentials
aws sts get-session-token \
--serial-number arn:aws:iam::769885837224:mfa/allen.luce \
--token-code `otp promethean-aws` \
--duration-seconds 129600 \
--profile mfa | \
jq -r '.Credentials
| "[default]",
"aws_access_key_id = \(.AccessKeyId)",
"aws_secret_access_key = \(.SecretAccessKey)",
"aws_session_token = \(.SessionToken)",
"# End of [default]"' >> ~/.aws/credentials
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment