Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import boto
- import datetime
- from datetime import date, timedelta
- import subprocess
- import os
- import argparse
- from boto.s3.connection import S3Connection
- from boto.sts import STSConnection
- import shutil
- #command line arguments
- parser = argparse.ArgumentParser(description='To create Temp credentials through STS function and upload to ~/.aws/credentials')
- parser.add_argument('-d', '--device_id', help='acc xxxxxxxx neumerical value', required=True)
- parser.add_argument('-u', '--user_id', help='user id like xxx ', required=True)
- parser.add_argument('-p', '--parent_profile', help='parent profile ', required=True)
- parser.add_argument('-m', '--mfa_profile', help='profile', required=True)
- args = parser.parse_args()
- deviceId = args.device_id
- userID = args.user_id
- parentProfile = args.parent_profile
- mfaProfile = args.mfa_profile
- # Prompt for MFA time-based one-time password (TOTP)
- mfa_TOTP = raw_input("Enter the MFA code: ")
- print "STS connection"
- #sts connection
- sts_connection = STSConnection(profile_name=parentProfile)
- print "STS connection temp credentials"
- tempCredentials = sts_connection.get_session_token(
- duration=43200,
- mfa_serial_number="arn:aws:iam::" + deviceId + ":mfa/" + userID,
- mfa_token=mfa_TOTP
- )
- print "STS connection temp credentials closed"
- print str(tempCredentials.access_key)
Add Comment
Please, Sign In to add comment