import boto
import boto3
from boto.s3.connection import S3Connection
from boto.sts import STSConnection
# Prompt for MFA time-based one-time password (TOTP)
mfa_TOTP = raw_input("Enter the MFA code: ")
role_arn = "arn:aws:iam::123456789012:role/TestOperator"
client = boto3.client('sts')
response = client.assume_role(RoleArn=role_arn,SerialNumber="arn:aws:iam::760787039612:mfa/C34768",RoleSessionName="test",TokenCode=mfa_TOTP)
print response
使用有效的 MFA TokenCode 运行上述代码时,也会出现以下错误
ClientError:调用 AssumeRole 操作时发生错误 (AccessDenied):MultiFactorAuthentication failed with invalid MFA one time pass code。
感谢帮助