Last active
March 31, 2017 14:35
-
-
Save danajp/fb706f46ed350f4fb1b1979d50ec301b to your computer and use it in GitHub Desktop.
Load aws credentials into environment variables
This file contains hidden or 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/env python | |
from __future__ import print_function | |
import sys | |
try: | |
import ConfigParser as configparser | |
except ImportError: | |
import configparser | |
def main(argv): | |
file = argv[1] | |
role = argv[2] | |
config = configparser.ConfigParser() | |
config.read(file) | |
if role not in config.sections(): | |
return | |
keys = ['aws_access_key_id', 'aws_secret_access_key', 'aws_session_token'] | |
for key in keys: | |
v = config.get(role, key) | |
print('export %s="%s"' % (key.upper(), v)) | |
main(sys.argv) |
This file contains hidden or 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
eval "$(python load-credentials.py ~/.aws/credentials support-mfa)" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment