cfn-lint, cloudformation template validation at time of commit

1 min read

This is amazing. You simply must add this into your IaaC development processes.

https://aws.amazon.com/blogs/mt/git-pre-commit-validation-of-aws-cloudformation-templates-with-cfn-lint/

From the article:

Save the file, then go ahead and try to commit it to your repo.

git add /templates/bad-reoutetable-association.yaml
git commit -m "Bring the badness"

You should see results similar to the following:

[INFO] Installing environment for https://github.com/awslabs/cfn-python-lint.
[INFO] Once installed this environment will be reused.
[INFO] This may take a few minutes...
AWSLabs CloudFormation Linter............................................Failed
hookid: cfn-python-lint

W2001 Parameter PrivateSubnet01 not used.
templates/bad-route-table-association.yaml:15:3

E3022 SubnetId in PublicSubnetRouteTableAssociation1 is also associated with PrivateSubnetRouteTableAssociation1
templates/bad-route-table-association.yaml:24:9

E3022 SubnetId in PrivateSubnetRouteTableAssociation1 is also associated with PublicSubnetRouteTableAssociation1
templates/bad-route-table-association.yaml:30:9<