Skip to content

Instantly share code, notes, and snippets.

@kg6zjl
Created February 23, 2019 14:13
Show Gist options
  • Select an option

  • Save kg6zjl/047cac65225ff5a0acd50ec751f7128a to your computer and use it in GitHub Desktop.

Select an option

Save kg6zjl/047cac65225ff5a0acd50ec751f7128a to your computer and use it in GitHub Desktop.
Create env vars from single section of ~/.aws/credentials, and set as default.
function activate() { #choose aws creds to push to env vars (example: activate sre-dev)
unset AWS_DEFAULT_PROFILE AWS_PROFILE AWS_SESSION_TOKEN AWS_SECRET_ACCESS_KEY AWS_ACCESS_KEY_ID AWS_SECURITY_TOKEN
eval $(python3 $HOME/git/dotfiles/files/python-ini.py $HOME/.aws/credentials $1)
}
#!/usr/bin/python3
import configparser
import sys
config = configparser.ConfigParser()
config.read(sys.argv[1])
#remove default
if config.has_section('default'):
config.remove_section('default')
config.write(open(sys.argv[1],'w'))
#create/recreate default
if not config.has_section('default'):
config.add_section('default')
for l in config[sys.argv[2]]:
print("export",l.upper()+"="+config[sys.argv[2]][l])
config.set('default', l, config[sys.argv[2]][l])
#write to file
config.write(open(sys.argv[1],'w'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment