The CLI can manage this a lot if you use roles. Described here: http://docs.aws.amazon.com/cli/latest/userguide/cli-roles.html
In my credentials file, I have:
[my_iam_user] aws_access_key_id = AKIABLAHBLAHBLAHBLAH aws_secret_access_key = <blah> region = us-east-1 [my_admin_role] role_arn = arn:aws:iam::123456789123:role/my_admin_role source_profile = my_iam_user mfa_serial = arn:aws:iam::123456789123:mfa/my_iam_user region = us-east-1
Pay attention to the mfa_serial entry. You can get this value from your user data in the AWS IAM console. This entry tells the CLI that an MFA is required for this role.
When I call aws s3 ls --profile my_admin_role , it says Enter MFA code: after I paste the code, it returns a list.
Note. I did not find a way to force the CLI to request MFA when invoking the user profile ( --profile my_iam_user ), only --profile my_iam_user role profile launches the MFA request.
Then the MFA token is pushed forward, and the user profile can also be used:
aws sts get-caller-identity --profile my_iam_user # { # "Account": "123456789123", # "UserId": "AIDABLAHBLAHBLAHBLAH", # "Arn": "arn:aws:iam::123456789123:user/my_iam_user" # } aws sts get-caller-identity --profile my_admin_role # { # "Account": "123456789123", # "UserId": "AROABLAHBLAHBLAHBLAH:AWS-CLI-session-1234567890", # "Arn": "arn:aws:sts::123456789123:assumed-role/my_admin_role/AWS-CLI-session-1234567890" # }
Joe harris
source share