Skip to content

Instantly share code, notes, and snippets.

@neerajjose
Last active March 28, 2020 17:01
Show Gist options
  • Select an option

  • Save neerajjose/b4ed6ff41ebc746ef1e80df5e974453d to your computer and use it in GitHub Desktop.

Select an option

Save neerajjose/b4ed6ff41ebc746ef1e80df5e974453d to your computer and use it in GitHub Desktop.
#! /usr/bin/env python
# Author: Neeraj
# Email: neerajjose@gmail.com
import configparser
from consolemenu import SelectionMenu
def load_config(file):
config = configparser.ConfigParser()
config.read(file)
return(config,config.sections())
def show_menu(menu):
try:
return(menu[SelectionMenu.get_selection(title="AWS Credential Manager", subtitle="Select a profile ", strings=menu)])
except:
exit(1)
## config file
AWS_CRED_FILE='/home/user/.aws/credentials'
config, menu=load_config(AWS_CRED_FILE)
profile = show_menu(menu)
config['default']['aws_access_key_id'] = config[profile]['aws_access_key_id']
config['default']['aws_secret_access_key'] = config[profile]['aws_secret_access_key']
with open(AWS_CRED_FILE, 'w') as configfile:
config.write(configfile)
@neerajjose
Copy link
Author

A simple menu driven script to manage aws credentials profiles.

Replace value for AWS_CRED_FILE with the correct path to credential file.

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