Skip to content

Instantly share code, notes, and snippets.

@mgla
Last active June 7, 2018 12:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mgla/bf028fbb73c7b8365fe41dccac0d0935 to your computer and use it in GitHub Desktop.
Save mgla/bf028fbb73c7b8365fe41dccac0d0935 to your computer and use it in GitHub Desktop.
AWS boto don't ask for token every time
#!/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