How To - Install the CFN-LINT CloudFormation Extension for Microsoft Visual Studio Code

The Cfn-Linter extension for the Microsoft Visual Studio Code (hereafter referred to as vscode) editor can be a major help to anyone asked to write AWS ClouidFormation Templates. Using a linter may be new to some. Linters are like Grammarly for your code. A good linter will alert you to mistakes before you attempt to compile or otherwise execute your code. Cfn-lint is like Grammarly for CloudFormation.

The extension uses Cfn-Python-Linter (https://github.com/aws-cloudformation/cfn-python-lint) to provide validation of AWS CloudFormation templates.

The install of the cfn-lint extension is similar to that of other extensions except there are some pre-requisites that must be met. The cfn-linter requires cfn-python-linter, which in turn requires python and pip.extensions

Install Prerequisites

Install cfn-python-linter as documented in a previous blog post

Install Extension

Select Extensions

vscode_extension__screenshot_01.png

Search cfn-lint

vscode_cfn-linter_screenshot_02.png

Select Install

vscode_cfn-lint_extension_screenshout_03.png

Close and Restart the vscode Editor

Validate the Extension

When the extension is running, it acts a lot like any other grammar checker you might see an application. A line shows up underneath a trouble spot. When you mouse over the word, the recommendation appears on the screen.

In my particular example, I was warned against hard coding the availability zone. A link is also included to find out more about the recommendation.

vscode_cfn_lint_screenshot_04.png

In addition, there is an option to “peek problem” which displays the problem in much better font and overall layout. From there, it’s possible to cycle through all issues in the code one by one.

Screen Shot 2020-04-02 at 9.53.35 PM.png

Summary

Cfn-lint is a pretty cool tool that should be a part of anyone’s toolkit who writes CloudFormation templates. I’d been wanting to try this out personally for a while now, but the installation seemed more complex than I was willing. By going through the steps, I see now that it’s not as difficult as I first believed. It just takes a little forethought. Hopefully, I’ve been able to share how easy it is.