How to Validate an AWS CloudFormation Template
The AWS CLI comes with a useful subcommand to validate a CloudFormation template.
This catches syntax errors and basic structural issues before you try to create or update a stack, which saves you from waiting for a rollback on a broken template. I run this as part of my CI pipeline so bad templates never make it to deployment.
Simply run the following to validate a CloudFormation template file:
aws cloudformation validate-template --template-body file://cf-infra.yaml
Remember to swap out cf-infra.yaml with your CloudFormation template file.
Keep in mind that this only checks if the template is valid JSON/YAML and that the structure follows CloudFormation syntax. It won’t catch issues like invalid resource property values or IAM permission problems — those only surface during actual stack creation. For deeper validation, tools like cfn-lint are worth adding to your workflow.