Created
November 6, 2015 19:36
-
-
Save justinian/8aa0bb422959fa948a4d to your computer and use it in GitHub Desktop.
AWS credential exporter from .aws/credentials to environment vairables
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/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() |
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
eval $(awsexport) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment