Last active
September 18, 2023 09:27
-
-
Save TomLous/a716d69d89e947a300766208de9a232b to your computer and use it in GitHub Desktop.
Set AWS tokens for MFA from CLI using 1password
This file contains hidden or 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
unset AWS_ACCESS_KEY_ID | |
unset AWS_SECRET_ACCESS_KEY | |
unset AWS_SESSION_TOKEN | |
OTP_ID=$1 | |
OTP=$(op item get $OTP_ID --otp) | |
DEVICE_ID=$(aws iam list-mfa-devices | jq -r '.MFADevices[0].SerialNumber') | |
RESULT=$(aws sts get-session-token --serial-number $DEVICE_ID --duration-seconds 129600 --token-code $OTP) | |
export AWS_ACCESS_KEY_ID=$(echo $RESULT | jq -r '.Credentials.AccessKeyId') | |
export AWS_SECRET_ACCESS_KEY=$(echo $RESULT | jq -r '.Credentials.SecretAccessKey') | |
export AWS_SESSION_TOKEN=$(echo $RESULT | jq -r '.Credentials.SessionToken') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
after getting these errors: