Skip to main content
This lesson continues the walkthrough for applying cfn-lint to AWS CloudFormation templates. By now you should have Python installed on your machine. We’ll install cfn-lint, run it against a minimal template, and review common errors it detects so you can fix templates before deployment.

Example minimal CloudFormation template (s3-bucket.yaml)

Install cfn-lint

  • Open Visual Studio Code and open the integrated terminal (View → Terminal or the toggle panel icon).
  • Install cfn-lint using pip:
The installer will fetch cfn-lint and its dependencies; this may take a minute. After installation, restart Visual Studio Code to ensure the editor picks up newly installed tools and any language extensions. If you need to re-open your project folder in VS Code:
A dark-themed Visual Studio Code window with an "Open Folder" dialog open showing a Desktop folder named "cf-project." The Windows taskbar and system tray are visible along the bottom of the screen.

Validate a template with cfn-lint

With your S3 template file open (s3-bucket.yaml), run cfn-lint from the terminal:
  • A successful run produces no error output — cfn-lint returns without printing errors or warnings.
  • If it finds issues, cfn-lint prints descriptive error codes and locations so you can quickly correct the template.

Common errors cfn-lint catches (examples and fixes)

Below are several typical mistakes and how cfn-lint helps identify them.
  1. Indentation / YAML structure errors
    Incorrect YAML indentation can cause the parser to miss required top-level keys such as Resources. Example malformed YAML (no indentation):
Running cfn-lint reports schema errors like:
Explanation: Because the nested resource names and Type values are not correctly indented under the Resources mapping, the linter interprets them as unexpected top-level properties. Correcting indentation to:
resolves these errors.
  1. Simple spelling / key name mistakes
    Using an incorrect key such as Resource (singular) instead of Resources (plural) triggers clear messages:
Example incorrect key:
cfn-lint output may include:
Fixing the key to Resources and re-running cfn-lint returns no errors:
Use cfn-lint on every CloudFormation template you author. It catches YAML formatting issues, schema problems, misspelled keys, and provides actionable error messages so templates are ready for deployment.

Quick reference — Common lint error types

Best practices

  • Run cfn-lint as part of your local development workflow and CI pipelines to catch issues early.
  • Combine cfn-lint with template formatting tools (like prettier for YAML or an editor extension) to keep templates consistent.
  • Refer to the CloudFormation resource specification when a property is unclear.

Summary

  • Install cfn-lint via pip in your development environment.
  • Restart VS Code after installation if needed.
  • Run cfn-lint against each template (example: cfn-lint s3-bucket.yaml).
  • Fix indentation, spelling, and schema issues the linter reports.
  • Repeat linting until the command completes without errors, indicating the template is valid and ready for CloudFormation.

Watch Video