{"id":1956,"library":"cfn-flip","title":"AWS CloudFormation Template Flip","description":"cfn-flip is a Python library and command-line tool for converting AWS CloudFormation templates between JSON and YAML formats, making use of YAML's short function syntax where possible. The library is currently at version 1.3.0, with the last release in 2021, suggesting a maintenance rather than active rapid development cadence for the core library, though the CLI usage is deprecated.","status":"active","version":"1.3.0","language":"en","source_language":"en","source_url":"https://github.com/awslabs/aws-cfn-template-flip","tags":["AWS","CloudFormation","YAML","JSON","template","conversion","Infrastructure as Code"],"install":[{"cmd":"pip install cfn-flip","lang":"bash","label":"Install with pip"}],"dependencies":[],"imports":[{"note":"General conversion function, attempts to detect input format.","symbol":"flip","correct":"from cfn_flip import flip"},{"note":"Converts a JSON or YAML string to YAML format.","symbol":"to_yaml","correct":"from cfn_flip import to_yaml"},{"note":"Converts a JSON or YAML string to JSON format.","symbol":"to_json","correct":"from cfn_flip import to_json"}],"quickstart":{"code":"from cfn_flip import to_yaml, to_json\n\njson_template = '''\n{\n  \"AWSTemplateFormatVersion\": \"2010-09-09\",\n  \"Description\": \"Example JSON template\",\n  \"Resources\": {\n    \"MyS3Bucket\": {\n      \"Type\": \"AWS::S3::Bucket\",\n      \"Properties\": {\n        \"BucketName\": \"my-unique-example-bucket\"\n      }\n    }\n  }\n}\n'''\n\nyaml_output = to_yaml(json_template)\nprint(\"--- JSON to YAML ---\")\nprint(yaml_output)\n\nyaml_template = '''\nAWSTemplateFormatVersion: '2010-09-09'\nDescription: Example YAML template\nResources:\n  MyLambdaFunction:\n    Type: AWS::Lambda::Function\n    Properties:\n      Handler: index.handler\n      Role: !GetAtt MyLambdaRole.Arn\n      Code:\n        S3Bucket: my-code-bucket\n        S3Key: my-code.zip\n      Runtime: python3.9\n'''\n\njson_output = to_json(yaml_template)\nprint(\"\\n--- YAML to JSON ---\")\nprint(json_output)\n","lang":"python","description":"This quickstart demonstrates how to use the `to_yaml` and `to_json` functions to convert CloudFormation templates between JSON and YAML formats within a Python script. It shows conversion from a JSON string to YAML and from a YAML string to JSON."},"warnings":[{"fix":"Migrate CLI usage from `cfn-flip` to `rain fmt`. For example, `cfn-flip -j template.yaml` becomes `rain fmt template.yaml --json`.","message":"The command-line interface (CLI) of `cfn-flip` is officially deprecated. Users are advised to use `rain fmt` from the `aws-cloudformation/rain` project for CLI-based template formatting and conversion instead.","severity":"deprecated","affected_versions":"All versions (deprecation announced in 1.3.0 README)"},{"fix":"When converting from JSON to YAML, consider using the `--long` option with the `cfn-flip` CLI (if still using it) or manually ensuring long-form function syntax in the YAML output to avoid unexpected resource replacements. Thoroughly review CloudFormation Change Sets before execution after conversion.","message":"Converting JSON templates to YAML using `cfn-flip`'s default shorthand syntax for intrinsic functions (e.g., `!Ref`, `!GetAtt`) can unexpectedly cause CloudFormation Change Sets to propose resource replacement instead of modification, even if no logical change occurred. This can lead to unintended downtime or data loss.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Be aware of this limitation and ensure important contextual information is not solely reliant on YAML comments if JSON conversion is part of your workflow. Consider documenting templates externally or retaining the YAML source if comments are critical.","message":"When converting a CloudFormation template from YAML to JSON format using `cfn-flip`, any comments present in the original YAML template will be lost in the resulting JSON output, as JSON does not natively support comments.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Adhere strictly to the YAML specification (e.g., use spaces for indentation, not tabs) to ensure compatibility with `cfn-flip` and other YAML tooling like `cfn-lint`. This generally leads to more robust and portable templates.","message":"`cfn-flip` uses a YAML parser that is more strict than the AWS CloudFormation service itself. This means that `cfn-flip` might flag certain YAML syntax issues (e.g., using tabs instead of spaces for indentation) as errors, even though CloudFormation might accept them.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-09T00:00:00.000Z","next_check":"2026-07-08T00:00:00.000Z"}