Skip to content

Instantly share code, notes, and snippets.

@danajp
Last active March 31, 2017 14:35
Show Gist options
  • Save danajp/fb706f46ed350f4fb1b1979d50ec301b to your computer and use it in GitHub Desktop.
Save danajp/fb706f46ed350f4fb1b1979d50ec301b to your computer and use it in GitHub Desktop.
Load aws credentials into environment variables
#!/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)
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