cfnjsontoyaml
Convert JSON CloudFormation templates to the new YAML syntax. This includes converting all Fn::* and Ref JSON functions to !* yaml node type functions.
In addition, cfnjsontoyaml tries to make a best guess at when Fn::Join functions should automatically be converted to !Sub.
Convert Long JSON to compact YAML
This utility not only converts from JSON to yaml, it will use the new short yaml syntax, and attempt to convert Fn::Join to !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.png
Usage
cfn-json-to-yaml reads 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-yaml
Examples
APIGateway Method with lambda proxy
In 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:
- LambdaInvokePermissionMappingReference
Problems
There 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 an issue 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 to https://github.com/drewsonne/cfn-json-to-yaml/tree/master/tests/resources/fragments with the next sequential number. The smaller the json/yaml snippet you can provide the quicker I can fix it. :-)
Metadata
Release files for cfnjsontoyaml 1.0.5
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| cfnjsontoyaml-1.0.5.tar.gz | 8.6 kB | Without provenance | Details for cfnjsontoyaml-1.0.5.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| cfnjsontoyaml-1.0.5-py2.py3-none-any.whl | Python 2, Python 3 | none | any | Details for cfnjsontoyaml-1.0.5-py2.py3-none-any.whl |
Total release size: 25.0 kB
Release files / cfnjsontoyaml-1.0.5.tar.gz
| Download URL | cfnjsontoyaml-1.0.5.tar.gz |
|---|---|
| Size | 8.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ad2c67f196968f010eb065986c07b155611339e40b03f41d90a22243e1b8330b
|
|
BLAKE2b-256 checksum How to use checksums |
89b1d0fc3a92f86eb91c18b42be95c9036ac1e8d4cb4a33302ec4fa102c6d605
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Release files / cfnjsontoyaml-1.0.5-py2.py3-none-any.whl
| Download URL | cfnjsontoyaml-1.0.5-py2.py3-none-any.whl |
|---|---|
| Size | 16.4 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
239e876a58c6a961ad1bbf5d06c7a88a05f7a325b14a54b8ef8928785bd96a2e
|
|
BLAKE2b-256 checksum How to use checksums |
45462e50bc2586a631083ff235833f1f6afcfd05c8e08f974ffa0861a8e376e6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for cfnjsontoyaml 1.0.5
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.