Created
June 29, 2023 21:13
-
-
Save vec715/2e4a75aeeb5fb0c522514bc0c42c7454 to your computer and use it in GitHub Desktop.
Parse AWS JSON ENV into .env format
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
import json | |
def aws_json_to_env(input_json): | |
with open('.env', 'w') as file: | |
for item in input_json: | |
try: | |
file.write(f'{item["name"]}={item["value"]}\n') | |
except TypeError: | |
print(f"Expected a dictionary, but got: {item}") | |
except KeyError: | |
print(f"Expected keys 'name' and 'value' in dictionary, but got: {item}") | |
# Test the function | |
json_input = [ | |
{ | |
"name": "foo", | |
"value": "bar" | |
} | |
] | |
aws_json_to_env(json_input) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment