Skip to content

Instantly share code, notes, and snippets.

@Vinlock
Created September 14, 2017 22:43
Show Gist options
  • Save Vinlock/35eac7765c76b0e8945384fbcb712854 to your computer and use it in GitHub Desktop.
Save Vinlock/35eac7765c76b0e8945384fbcb712854 to your computer and use it in GitHub Desktop.
AWSCLI Cert Uploader/Generator
#!/usr/bin/env python
import argparse, os, readline
# Check if AWS CLI is installed
if os.popen("command -v aws").read() == '':
print('AWS Command Line Interface is not installed.')
exit()
# Parse Arguments
parser = argparse.ArgumentParser()
parser.add_argument('--type', help='Cloudfront Cert = cloudfront', default='none')
args = parser.parse_args()
# Output
os.system('clear')
print(" ______ __ __ ____ ____ __ ")
print("/\ _ \/\ \ __/\ \/\ _`\ /\ _`\ /\ \__")
print("\ \ \L\ \ \ \/\ \ \ \ \,\L\_\ \ \ \/\_\ __ _ __\ \ ,_\\")
print(" \ \ __ \ \ \ \ \ \ \/_\__ \ \ \ \/_/_ /'__`\/\`'__\ \ \/")
print(" \ \ \/\ \ \ \_/ \_\ \/\ \L\ \ \ \ \L\ \/\ __/\ \ \/ \ \ \_")
print(" \ \_\ \_\ `\___x___/\ `\____\ \ \____/\ \____\\\\ \_\ \ \__\\")
print(" \/_/\/_/'\/__//__/ \/_____/ \/___/ \/____/ \/_/ \/__/")
print(" ")
print(" ")
print(" ____ __ ")
print("/\ _`\ /\ \__ ")
print("\ \ \L\_\ __ ___ __ _ __ __ \ \ ,_\ ___ _ __ ")
print(" \ \ \L_L /'__`\/' _ `\ /'__`\/\`'__\/'__`\ \ \ \/ / __`\/\`'__\\")
print(" \ \ \/, \/\ __//\ \/\ \/\ __/\ \ \//\ \L\.\_\ \ \_/\ \L\ \ \ \/ ")
print(" \ \____/\ \____\ \_\ \_\ \____\\\\ \_\\\\ \__/.\_\\\\ \__\ \____/\ \_\ ")
print(" \/___/ \/____/\/_/\/_/\/____/ \/_/ \/__/\/_/ \/__/\/___/ \/_/ ")
print('')
print('Instructions:')
print(' - Must be ran in the directory with the cert files in it.')
print(' - Type the full filename of the cert files.')
print('')
print('==========================================')
print('=== Files in current working directory ===')
print('==========================================')
print('')
os.system('ls -als')
print('')
print('==========================================')
print('')
if (args.type == 'cloudfront'):
print('AWS Cloudfront Certicate Uploader (Press ^C to Cancel)')
else:
print('AWS ELB/ACM Certicate Uploader (Press ^C to Cancel)')
print('')
# Input
try:
cert_name = raw_input('Certificate Name: ')
crt_file = raw_input('CRT File (.crt): ')
key_file = raw_input('Key File (.key): ')
intermediate = raw_input('IntermediateCA (.crt): ')
# Generate Command
if args.type == 'cloudfront':
cloudfront_distribution = raw_input('Cloudfront Distribution: ')
path = '/cloudfront/'+cloudfront_distribution
command = "aws iam upload-server-certificate --server-certificate-name %s -- certificate-body file://%s --private-key file://%s --certificate-chain file://%s --path %s" % (cert_name, crt_file, key_file, intermediate, path)
else:
command = 'aws acm import-certificate --certificate file://%s --private-key file://%s --certificate-chain file://%s' % (crt_file, key_file, intermediate)
os.system(command)
except KeyboardInterrupt:
print('\n > Cancelled Certificate creation.')
exit()
exit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment