Created
February 13, 2018 18:22
-
-
Save denniswebb/024041c04744bf9cbd61d1183602c6db to your computer and use it in GitHub Desktop.
Creates MFA AWS Profile for base profile
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
#!/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