Using a linter for best practices on templates
Let's describe a linter again. This is how Wikipedia defines a linter:
"Lint, or a linter, is a tool that analyzes source code to flag programming errors, bugs, stylistic errors, and suspicious constructs."
CloudFormation's linter, known as a cfn-lint
, is a command-line tool that inspects your template and compares the declared resources against a wide range of written rules.
Unlike the template validator, cfn-lint
can detect tricky issues such as missing resource properties or arguments in an intrinsic function.
CloudFormation's linter is an external tool that can be installed using pip
:
$ pip install cfn-lint
It will automatically appear in $PATH
, so we can run it right away:
$ cfn-lint core.yaml
If the template meets all the rule requirements, we will see nothing on the output (and the return code of the command will be 0
). However, if there is an error, the linter will notify us immediately...