Skip to content

Instantly share code, notes, and snippets.

@svrist
Created February 7, 2017 21:43
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save svrist/d03f0dffefb215f1b8843176e9f48d59 to your computer and use it in GitHub Desktop.
Save svrist/d03f0dffefb215f1b8843176e9f48d59 to your computer and use it in GitHub Desktop.
export cloudformation outputs as more simple json
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