Created
August 17, 2020 22:12
-
-
Save antgel/32cedc6907f37f8297938b58a5d9af04 to your computer and use it in GitHub Desktop.
This file contains 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 | |
# On Amazon Linux 2, when you ssh into an instance, the Elastic Beanstalk environment variables are | |
# not set. This is annoying when trying to reproduce production issues. I dug for a while, couldn't | |
# find any documentation on this, then rolled my own solution. NB AL2 has Python 2 not 3 *sigh* | |
# Usage: | |
# Save this file on the instance, I suggest the name eb-env-generator.py | |
# | |
# python eb-env-generator.py | |
# | |
# This outputs a file called eb-envvars.sh which contains all the commands to set and export | |
# the variables to the shell | |
# | |
# . eb-envars.sh | |
# ^^^ Note the full stop syntax to source the file. | |
import json | |
import os | |
import subprocess | |
output = subprocess.check_output('/opt/elasticbeanstalk/bin/get-config environment', shell=True) | |
vars = json.loads(output) | |
file = open("eb-envvars.sh", "w") | |
file.write("#!/bin/sh\n") | |
for key, value in vars.iteritems(): | |
file.write("export " + key + "=\"" + value + "\"\n") | |
file.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment