Last active
December 21, 2021 02:45
-
-
Save jairamc/f6104ec0a41a6699b2ddfaef498e0009 to your computer and use it in GitHub Desktop.
Simple python script to set AWS Credentials in your 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 | |
############################################################### | |
# In your .bashrc/.zshrc add `eval $(python <path to script>)` | |
# Or simply run `eval $(python <path to script>)` | |
# This avoids adding your aws credentials to bash/zsh history | |
############################################################### | |
import os, sys | |
from ConfigParser import ConfigParser | |
def setAwsCredentials(args): | |
config = ConfigParser() | |
if len(args) > 1: | |
conf.read(args[1]) | |
else: | |
config.read(os.getenv("HOME") + "/.aws/credentials") | |
print "export AWS_ACCESS_KEY_ID=%s AWS_SECRET_ACCESS_KEY=%s && echo 'aws credentials set'" % ( | |
config.get("default", "aws_access_key_id"), config.get("default", "aws_secret_access_key")) | |
if __name__ == "__main__": | |
setAwsCredentials(sys.argv) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for sharing this code!
I needed to un-capitalize the configparser's import, like so: