Package: cfnjsontoyaml
cfnjsontoyamlConvert JSON CloudFormation templates to the new YAML syntax. This
includes converting allFn::*andRefJSON functions to!*yaml node type functions.In addition, cfnjsontoyaml tries to make a best guess at whenFn::Joinfunctions should automatically be converted to!Sub.Convert Long JSON to compact YAMLThis utility not only converts from JSON to yaml, it will use the new
short yaml syntax, and attempt to convertFn::Jointo!Sub,
resulting in shorter, more compact syntax.For example, and IAM role can be converted from 127 lines of JSON
cloudformation to 30 lines of yaml.docs/images/diagram.pngUsagecfn-json-to-yamlreads either from standard in, or takes the first
argument as the template to ingest and prints the yaml converted
template to stdout.$ pip install cfnjsontoyaml
$ cat my_template.json | cfn-json-to-yamlExamplesAPIGateway Method with lambda proxyIn some cases, we can halve the number of lines, while still maintaining
readability. Here, we convert 48 lines of JSON to 19 lines of YAML. ####
JSON{
  "Resources": {
    "MappingReferenceMethod": {
      "Type": "AWS::ApiGateway::Method",
      "DependsOn": [
        "LambdaInvokePermissionMappingReference"
      ],
      "Properties": {
        "RestApiId": {
          "Ref": "RestApi"
        },
        "ResourceId": {
          "Ref": "MappingReferenceResource"
        },
        "HttpMethod": "POST",
        "AuthorizationType": "NONE",
        "ApiKeyRequired": true,
        "RequestParameters": {
          "method.request.header.x-api-key": true
        },
        "Integration": {
          "Type": "AWS_PROXY",
          "Uri": {
            "Fn::Join": [
              "",
              [
                "arn:aws:apigateway:",
                {
                  "Ref": "AWS::Region"
                },
                ":lambda:path/2015-03-31/functions/",
                {
                  "Fn::GetAtt": [
                    "LambdaFunctionMappingReference",
                    "Arn"
                  ]
                },
                "/invocations"
              ]
            ]
          },
          "IntegrationHttpMethod": "POST",
          "PassthroughBehavior": "when_no_templates"
        }
      }
    }
  }
}YAML---
Resources:
  MappingReferenceMethod:
    Type: AWS::ApiGateway::Method
    Properties:
      ApiKeyRequired: true
      AuthorizationType: NONE
      HttpMethod: POST
      Integration:
        IntegrationHttpMethod: POST
        PassthroughBehavior: when_no_templates
        Type: AWS_PROXY
        Uri: !Sub "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${LambdaFunctionMappingReference.Arn}/invocations"
      RequestParameters:
        method.request.header.x-api-key: true
      ResourceId: !Ref "MappingReferenceResource"
      RestApiId: !Ref "RestApi"
    DependsOn:
    - LambdaInvokePermissionMappingReferenceProblemsThere are a wide range of combinations for functions in cloudformation.
If you come across a template which does not render correctly, please
try and isolate the fragment of json which is causing issues, and create
anissue in
github.If you’d like to be a bit more helpful, you can fork the repository,
create a branch, and add a json/yaml snippet tohttps://github.com/drewsonne/cfn-json-to-yaml/tree/master/tests/resources/fragmentswith the next sequential number. The smaller the json/yaml snippet you
can provide the quicker I can fix it. :-)