How do I type in the MFA code when using the AWS CLI? I have checked the documentation page of IAM http://docs.aws.amazon.com/cli/latest/reference/iam/index.html.
I
AWS MFA use on the command line can be rather unpleasant and cumbersome, especially if you have multiple profiles and roles.
I have released awscli-mfa.sh
script that makes MFA/role session management on the command line a lot easier. A companion script enable-disable-vmfa-device.sh
similarly makes it easy to enable or disable a virtual MFA device on an IAM user account.
awscli-mfa.sh
persists a started session in ~/.aws/credentials
(with some info in ~/.aws/config
), or allows you to start an in-env session only so that its details don't get persisted. When executed in Windows Subsystem for Linux, the script also provides session activation strings for PowerShell and Windows command line. However, the script itself only runs in bash (written for macOS, Linux, and WSL bash with Ubuntu).
You can find the scripts and the example MFA policies in my GitHub repo at https://github.com/vwal/awscli-mfa