Created
November 21, 2016 10:33
-
-
Save kj187/a8332d2b6dc517accedbff8fd8e63b08 to your computer and use it in GitHub Desktop.
Converting a CloudFormation Template from JSON to YAML
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 | |
## Converting a CloudFormation Template from JSON to YAML | |
## Script copyright: http://blog.flux7.com/how-to-convert-a-cloudformation-template-from-json-to-yaml | |
## | |
## Example: | |
## $ python converter.py --json my-stack.template --yaml my-stack.yaml | |
import yaml | |
import json | |
import argparse | |
import sys | |
if __name__ == "__main__": | |
parser = argparse.ArgumentParser() | |
parser.add_argument('--json', help='Input file (JSON)', required=True) | |
parser.add_argument('--yaml', help='Output file (YAML)', required=True) | |
if len(sys.argv) == 1: | |
parser.print_help() | |
sys.exit(1) | |
args = parser.parse_args() | |
json_file = args.json | |
yaml_file = args.yaml | |
with open(json_file) as fp: | |
json = json.load(fp) | |
with open(yaml_file, 'w') as yaml_fp: | |
yaml.safe_dump(json, yaml_fp, allow_unicode=True, default_flow_style=False) | |
print "Created YAML file {0}".format(yaml_file) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment