/aws-cloudformation-template-formatter

cfn-format is a command line tool and Go library that pretty-prints CloudFormation, adhering to the standards used in AWS documentation.

Primary LanguageGoApache License 2.0Apache-2.0

GitHub version Snap Status

Get it from the Snap Store

AWS CloudFormation Template Formatter

This repository contains cfn-format, a command line tool that reads in an existing AWS CloudFormation template and outputs a cleanly-formatted, easy-to-read copy of the same template adhering to standards as used in AWS documentation. cfn-format can output either YAML or JSON as desired.

License

This project is licensed under the Apache 2.0 License.

Installation

You can install cfn-format in one of the following three ways:

  • Use the snap package

  • Download the latest release for your operating system.

  • If you have Go (v1.12 or higher) installed, run the following:

    GO111MODULE=on go get github.com/awslabs/aws-cloudformation-template-formatter/cmd/cfn-format

Usage

If you're using vim, you can add the following to your .vimrc to automate running cfn-format when you save a .template file:

autocmd BufWritePost *.template silent !cfn-format -w % 2>/dev/null

Command-line tool

Usage: cfn-format [OPTION...] [FILENAME]

  AWS CloudFormation Format is a tool that reads a CloudFormation template
  and outputs the same template, formatted according to the same standards
  used in AWS documentation.

  If FILENAME is not supplied, cfn-format will read from STDIN.

Options:
  --help    Show this message and exit.
  -c, --compact   Produce more compact output.
  -j, --json      Output the template as JSON (default format: YAML).
  -v, --verify    Check if the input is already correctly formatted and exit.
                  The exit status will be 0 if so and 1 if not.
  -w, --write     Write the output back to the file rather than to stdout.

Go package documentation

The parse and format packages have moved to become part of rain.

To see the current Go documentation, please check the Rain source code.