Created
February 7, 2017 21:43
-
-
Save svrist/d03f0dffefb215f1b8843176e9f48d59 to your computer and use it in GitHub Desktop.
export cloudformation outputs as more simple json
This file contains hidden or 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
from __future__ import division, print_function, unicode_literals | |
import json | |
import re | |
import boto3 | |
def main(stack): | |
cf = boto3.client('cloudformation') | |
r = cf.describe_stacks(StackName=stack) | |
stack, = r['Stacks'] | |
outputs = stack['Outputs'] | |
out = {} | |
for o in outputs: | |
key = _to_env(o['OutputKey']) | |
out[key] = o['OutputValue'] | |
print(json.dumps(out, indent=2)) | |
def _to_env(name): | |
s1 = re.sub('(.)([A-Z][a-z]+)', r'\1_\2', name) | |
return re.sub('([a-z0-9])([A-Z])', r'\1_\2', s1).upper() | |
if __name__ == '__main__': | |
import sys | |
main(sys.argv[1]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment