没有项目描述

cfnjsontoyaml的Python项目详细描述


PyPI version

Code Issues

codecov

Build Status

cfnjsontoyaml

将json cloudformation模板转换为新的yaml语法。这个 包括将所有Fn::*Refjson函数转换为!* yaml节点类型函数。

此外,cfnjsontoyaml试图对何时 Fn::Join函数应自动转换为!Sub

将长json转换为压缩yaml

此实用程序不仅将json转换为yaml,还将使用新的 简短的yaml语法,并尝试将Fn::Join转换为!Sub, 导致更短,更紧凑的语法。

例如,可以从127行json转换iam角色 30行山药形成云。

docs/images/diagram.png

docs/images/diagram.png

使用量

cfn-json-to-yaml从标准读入,或读取第一个 参数作为模板接收并打印转换的yaml 标准输出模板。

$ pip install cfnjsontoyaml
$ cat my_template.json | cfn-json-to-yaml

示例

apigateway方法,带有lambda代理

在某些情况下,我们可以将行数减半,同时仍然保持 可读性。在这里,我们将48行json转换为19行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"
        }
      }
    }
  }
}

山药
---
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:
    - LambdaInvokePermissionMappingReference

问题

云形成中的各种功能有多种组合。 如果遇到无法正确呈现的模板,请 尝试分离导致问题的json片段,并创建 一个issue in github

如果你想帮点忙的话,你可以用叉子叉仓库, 创建分支,并将json/yaml片段添加到 https://github.com/drewsonne/cfn-json-to-yaml/tree/master/tests/resources/fragments 下一个序列号。json/yaml代码段越小 我能尽快修好它。:-)

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
JAVAexe jar文件读取txt文件,但内容在不同的计算机中都被破坏(显示外来语言..)   java BufferedReader提供缺少的字符   java我希望全局捕获所有可能的安卓异常,以便应用程序无法关闭   java MATLAB JA Builder   java如何将一副牌一分为二?   字典在Java中使用映射条目时出错   Java命令提示符仿真器   java HC06蓝牙模块   如何在java中获得与CallableStatement一起使用的完全限定SQL类型名。registerOutParameter   java如何为文件中的每一行整数创建数组   java从文本框传递参数   java如何将参数传递到工厂以创建对象?   java JSP无法执行脚本标记中包含的javascript函数