Skip to content

Instantly share code, notes, and snippets.

@jairamc
Last active December 21, 2021 02:45
Show Gist options
  • Save jairamc/f6104ec0a41a6699b2ddfaef498e0009 to your computer and use it in GitHub Desktop.
Save jairamc/f6104ec0a41a6699b2ddfaef498e0009 to your computer and use it in GitHub Desktop.
Simple python script to set AWS Credentials in your environment variables
#! /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)
@monocongo
Copy link

Thanks for sharing this code!

I needed to un-capitalize the configparser's import, like so:

from configparser import ConfigParser

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment