Skip to content

Instantly share code, notes, and snippets.

@kmcquade
Created December 6, 2018 16:03
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save kmcquade/d7d05513dbcc27bb1d9bb74d038a07d0 to your computer and use it in GitHub Desktop.
Save kmcquade/d7d05513dbcc27bb1d9bb74d038a07d0 to your computer and use it in GitHub Desktop.
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