Linting and Static Code Analysis

Configure cfn-lint and Checkov to enforce code quality and security standards in your CloudFormation templates.


Overview

The starter kit includes pre-configured linting and security scanning that runs locally and in CI/CD. These tools catch errors early and ensure security compliance before infrastructure reaches production.

Tools included

ToolPurpose
cfn-lintValidates template syntax, resource properties, and AWS best practices
CheckovScans for security misconfigurations and compliance violations

Both tools run automatically via the validation script and in GitHub Actions.

cfn-lint configuration

The starter kit includes .cfnlintrc:

templates:
  - templates/*.yml
ignore_templates:
  - codebuild.yaml

What it validates

CheckDescription
Syntax errorsInvalid YAML/JSON structure
Resource propertiesRequired properties, valid values, types
AWS limitsResource name lengths, parameter counts
Best practicesProper use of Refs, GetAtt, intrinsic functions
Region availabilityResources available in target regions

Customization

Edit .cfnlintrc to add/remove template patterns or ignore rules. See the cfn-lint reference for complete documentation.

Checkov configuration

The starter kit includes .checkov.yml:

branch: main
directory:
  - templates
download-external-modules: false
evaluate-variables: true
external-modules-download-path: .external_modules
framework:
  - cloudformation
secrets-scan-file-type: []
skip-check:
  - CKV_AWS_7
  - CKV_AWS_18
  - CKV_AWS_21
  - CKV_AWS_62
  - CKV_AWS_107
  - CKV_AWS_108
  - CKV_AWS_109
  - CKV_AWS_110
  - CKV_AWS_111
  - CKV_AWS_115
  - CKV_AWS_116
  - CKV_AWS_117
  - CKV_AWS_157
  - CKV_AWS_162
  - CKV_SECRET_14

Configuration options

OptionDescription
frameworkSet to cloudformation for template scanning
directoryLists directories to scan
evaluate-variablesEvaluates CloudFormation parameters
skip-checkCheck IDs to skip (pre-configured exceptions)

Inline suppressions

Suppress checks for specific resources:

Resources:
  LogBucket:
    # checkov:skip=CKV_AWS_18:Access logging not required for log aggregation bucket
    Type: AWS::S3::Bucket
    Properties:
      BucketName: app-access-logs

Always include a justification explaining why the check is skipped.

See the Checkov reference for complete documentation.

Running validation

Via validation script

./scripts/validate-templates.sh

Runs Checkov security scanning on all templates using the .checkov.yml configuration.

Individual tools

# cfn-lint only
cfn-lint templates/*.yml

# Checkov only
checkov --directory templates/ --framework cloudformation

CI/CD integration

Both tools run automatically in GitHub Actions. Failed checks block the deployment pipeline, ensuring only validated and secure infrastructure reaches production.

See CI/CD Workflows for integration details.

Next steps