没有项目描述
cfnjsontoyaml的Python项目详细描述
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
使用量
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
山药
---
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代码段越小 我能尽快修好它。:-)