没有项目描述

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第三方库


热门话题
java楼梯的最大高度   java Jackson从1.7.1更新到2.8.6 JsonTypeInfo子类型反序列化   Spring WebApp中的java JPA异常处理   java在SwingWorker(doInBackground)中从WorkerThread调用多个方法?   java Android Studio构建到jar   java是添加多个按钮组的更有效方法   java MySQL JDBC连接池最大大小   java如何防止元素<Integer>变成元素<Object>   Java:处理大型XML文件提取数据而不编写状态自动机?   SpringBoot和React Web应用程序中CAS的java重定向问题   需要java算法方面的帮助吗   java在JDK 16中使用PowerMock   java异常错误本机方法签名   在Java Android中将JSON映射到数组/对象   如何打开一个窗口。java程序中的dat文件   java应用程序引擎+Maven+热插拔   java Moxy的getValueByXPath为除根元素以外的所有元素返回null