Guest User

Untitled

a guest
Dec 11th, 2017
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.33 KB | None | 0 0
  1. import boto
  2. import datetime
  3. from datetime import date, timedelta
  4. import subprocess
  5. import os
  6. import argparse
  7. from boto.s3.connection import S3Connection
  8. from boto.sts import STSConnection
  9. import shutil
  10.  
  11.  
  12.  
  13.  
  14.  
  15. #command line arguments
  16. parser = argparse.ArgumentParser(description='To create Temp credentials through STS function and upload to ~/.aws/credentials')
  17.  
  18. parser.add_argument('-d', '--device_id', help='acc xxxxxxxx neumerical value', required=True)
  19. parser.add_argument('-u', '--user_id', help='user id like xxx ', required=True)
  20. parser.add_argument('-p', '--parent_profile', help='parent profile ', required=True)
  21. parser.add_argument('-m', '--mfa_profile', help='profile', required=True)
  22.  
  23. args = parser.parse_args()
  24. deviceId = args.device_id
  25. userID = args.user_id
  26. parentProfile = args.parent_profile
  27. mfaProfile = args.mfa_profile
  28.  
  29.  
  30.  
  31. # Prompt for MFA time-based one-time password (TOTP)
  32. mfa_TOTP = raw_input("Enter the MFA code: ")
  33.  
  34. print "STS connection"
  35. #sts connection
  36. sts_connection = STSConnection(profile_name=parentProfile)
  37.  
  38.  
  39. print "STS connection temp credentials"
  40. tempCredentials = sts_connection.get_session_token(
  41. duration=43200,
  42. mfa_serial_number="arn:aws:iam::" + deviceId + ":mfa/" + userID,
  43. mfa_token=mfa_TOTP
  44. )
  45. print "STS connection temp credentials closed"
  46.  
  47. print str(tempCredentials.access_key)
Add Comment
Please, Sign In to add comment