Created
December 6, 2018 16:03
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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