I found an example for boto + MFA:
http://docs.aws.amazon.com/IAM/latest/UserGuide/id_credentials_mfa_sample-code.html
But I cannot find an example of how to do it with boto3. Any equivalent boto3 examples?
Thanks!
The code below works but you have to use ~/.boto file with the correct credentials. SerialNumber is your MFA device serial or the full AWS ARN of it
#!/usr/bin/env python
import boto3
mfa_TOTP = input("Enter the MFA code: ")
client=boto3.client('sts')
response = client.assume_role(
RoleArn='arn:aws:iam::123456789:role/admin_full',
RoleSessionName='mysession',
DurationSeconds=3600,
SerialNumber='arn:aws:iam::987654321:mfa/myaccount',
TokenCode=mfa_TOTP,
)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With