import boto
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: ")

# The calls to AWS STS GetSessionToken must be signed with the access key ID and secret
# access key of an IAM user. The credentials can be in environment variables or in 
# a configuration file and will be discovered automatically
# by the STSConnection() function. For more information, see the Python SDK 
# documentation: http://boto.readthedocs.org/en/latest/boto_config_tut.html

sts_connection = STSConnection()

# Use the appropriate device ID (serial number for hardware device or ARN for virtual device). 
# Replace ACCOUNT-NUMBER-WITHOUT-HYPHENS and MFA-DEVICE-ID with appropriate values.

tempCredentials = sts_connection.get_session_token(
    duration=3600,
    mfa_serial_number="arn:aws:iam::865489921604:user/rtripathi",
    mfa_token=mfa_TOTP
)

# Use the temporary credentials to list the contents of an S3 bucket
s3_connection = S3Connection(
    aws_access_key_id=tempCredentials.access_key,
    aws_secret_access_key=tempCredentials.secret_key,
    security_token=tempCredentials.session_token
)

# Replace BUCKET-NAME with an appropriate value.
for bucket in s3_resource.buckets.all():
    print(bucket.name)
f1c2ea94ab84d2abb2e1233fc9b5c57cb21fa29d
<mask token>

<mask token>
for bucket in s3_resource.buckets.all():
    print(bucket.name)

<mask token>
mfa_TOTP = raw_input('Enter the MFA code: ')
sts_connection = STSConnection()
tempCredentials = sts_connection.get_session_token(duration=3600,
    mfa_serial_number='arn:aws:iam::865489921604:user/rtripathi', mfa_token
    =mfa_TOTP)
s3_connection = S3Connection(aws_access_key_id=tempCredentials.access_key,
    aws_secret_access_key=tempCredentials.secret_key, security_token=
    tempCredentials.session_token)
for bucket in s3_resource.buckets.all():
    print(bucket.name)

import boto
from boto.s3.connection import S3Connection
from boto.sts import STSConnection
mfa_TOTP = raw_input('Enter the MFA code: ')
sts_connection = STSConnection()
tempCredentials = sts_connection.get_session_token(duration=3600,
    mfa_serial_number='arn:aws:iam::865489921604:user/rtripathi', mfa_token
    =mfa_TOTP)
s3_connection = S3Connection(aws_access_key_id=tempCredentials.access_key,
    aws_secret_access_key=tempCredentials.secret_key, security_token=
    tempCredentials.session_token)
for bucket in s3_resource.buckets.all():
    print(bucket.name)

import boto
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: ")

# The calls to AWS STS GetSessionToken must be signed with the access key ID and secret
# access key of an IAM user. The credentials can be in environment variables or in 
# a configuration file and will be discovered automatically
# by the STSConnection() function. For more information, see the Python SDK 
# documentation: http://boto.readthedocs.org/en/latest/boto_config_tut.html

sts_connection = STSConnection()

# Use the appropriate device ID (serial number for hardware device or ARN for virtual device). 
# Replace ACCOUNT-NUMBER-WITHOUT-HYPHENS and MFA-DEVICE-ID with appropriate values.

tempCredentials = sts_connection.get_session_token(
    duration=3600,
    mfa_serial_number="arn:aws:iam::865489921604:user/rtripathi",
    mfa_token=mfa_TOTP
)

# Use the temporary credentials to list the contents of an S3 bucket
s3_connection = S3Connection(
    aws_access_key_id=tempCredentials.access_key,
    aws_secret_access_key=tempCredentials.secret_key,
    security_token=tempCredentials.session_token
)

# Replace BUCKET-NAME with an appropriate value.
for bucket in s3_resource.buckets.all():
    print(bucket.name)