Skip to content

Instantly share code, notes, and snippets.

@justinian
Created November 6, 2015 19:36
Show Gist options
  • Save justinian/8aa0bb422959fa948a4d to your computer and use it in GitHub Desktop.
Save justinian/8aa0bb422959fa948a4d to your computer and use it in GitHub Desktop.
AWS credential exporter from .aws/credentials to environment vairables
#!/usr/bin/env python
import os
import os.path
from ConfigParser import SafeConfigParser
HOME = os.environ["HOME"]
CREDS = os.path.join(HOME, ".aws", "credentials")
def error(message):
import sys
sys.stderr.write(message)
sys.stderr.write("\n")
sys.exit(1)
def print_profile(profile):
cfg = SafeConfigParser()
cfg.read(CREDS)
if not cfg.has_section(profile):
error("No such profile: '%s'" % (profile,))
for key in ("aws_access_key_id", "aws_secret_access_key"):
print "export %s='%s'" % (key.upper(), cfg.get(profile, key))
def main():
import sys
if len(sys.argv) > 2:
error("Usage: %s [profile]" % (sys.argv[0],))
profile = "default"
if len(sys.argv) > 1:
profile = sys.argv[1]
print_profile(profile)
if __name__ == "__main__": main()
eval $(awsexport)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment