Last active
June 7, 2018 12:20
-
-
Save mgla/bf028fbb73c7b8365fe41dccac0d0935 to your computer and use it in GitHub Desktop.
AWS boto don't ask for token every time
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
# Don't ask for MFA token every time | |
from botocore import credentials | |
import botocore.session | |
import boto3 | |
import os | |
# Boto3 MFA session magic | |
working_dir = os.path.join(os.path.expanduser('~'),'.aws/cli/cache') | |
session = botocore.session.get_session() | |
provider = session.get_component('credential_provider').get_provider('assume-role') | |
provider.cache = credentials.JSONFileCache(working_dir) | |
client = boto3.Session(botocore_session=session).client('s3') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment