· 7 years ago · Dec 07, 2018, 12:00 AM
1#!/usr/bin/python2.7
2import ConfigParser
3import os
4import sys
5from os.path import expanduser
6
7config = ConfigParser.RawConfigParser()
8
9# credentials_file: The file where this script will grab the temp creds
10credentials_file = '/.aws/credentials'
11home = expanduser("~")
12credentials_file = home + credentials_file
13config.read(credentials_file)
14
15# Get the profile name to grab the credentials
16profile = raw_input('Profile: ')
17print ''
18
19# Get the credentials from the file
20access_key = config.get(profile, 'aws_access_key_id')
21secret_key = config.get(profile, 'aws_secret_access_key')
22session_token = config.get(profile, 'aws_session_token')
23
24print('export AWS_ACCESS_KEY_ID=' + access_key)
25print('export SECRET_ACCESS_KEY=' + secret_key)
26print('export SESSION_TOKEN=' + session_token)