Skip to content

Instantly share code, notes, and snippets.

@denniswebb
Created February 13, 2018 18:22
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save denniswebb/024041c04744bf9cbd61d1183602c6db to your computer and use it in GitHub Desktop.
Save denniswebb/024041c04744bf9cbd61d1183602c6db to your computer and use it in GitHub Desktop.
Creates MFA AWS Profile for base profile
#!/usr/bin/env bash
token=$1
aws_account=132456
base_profile=work
mfa_profile=workmfa
username=denniswebb
creds=$(aws --profile ${base_profile} sts get-session-token --serial-number arn:aws:iam::${aws_account}:mfa/${username} --duration 129600 --token $token --query "Credentials.[AccessKeyId, SecretAccessKey, SessionToken]" --output text)
if [ "$?" -ne "0" ]; then
echo $creds
exit 1
fi
echo $creds | awk '{system ("crudini --set ~/.aws/credentials '"${mfa_profile}"' aws_access_key_id " $1); system ("crudini --set ~/.aws/credentials '"${mfa_profile}"' aws_secret_access_key " $2); system ("crudini --set ~/.aws/credentials '"${mfa_profile}"' aws_session_token " $3)}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment