Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Simple python script to grab profile-specific keys from aws credentials file for environment variables export
#!/usr/bin/python2.7
import ConfigParser
import os
import sys
from os.path import expanduser
config = ConfigParser.RawConfigParser()
# credentials_file: The file where this script will grab the temp creds
credentials_file = '/.aws/credentials'
home = expanduser("~")
credentials_file = home + credentials_file
config.read(credentials_file)
# Get the profile name to grab the credentials
profile = raw_input('Profile: ')
print ''
# Get the credentials from the file
access_key = config.get(profile, 'aws_access_key_id')
secret_key = config.get(profile, 'aws_secret_access_key')
session_token = config.get(profile, 'aws_session_token')
print('export AWS_ACCESS_KEY_ID=' + access_key)
print('export SECRET_ACCESS_KEY=' + secret_key)
print('export SESSION_TOKEN=' + session_token)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment