Subchapter 29.13
references/validate-with-cfn-lint.script.mdMarkdown8 KBView on GitHub
Deterministic procedure for local CloudFormation template validation with cfn-lint. Use this SOP when the user explicitly requests cfn-lint, the project configures it, or it is already installed. Prefer the CLI; the Python API is also available for local validation.
["us-east-1", "eu-west-1"]). Defaults to cfn-lint’s default region if omitted.["W2001", "E3012"]).Constraints for parameter acquisition:
Check which validation mechanism is available.
Constraints:
cfn-lint CLI available on the user’s system (verify with which cfn-lint or cfn-lint --version)cfnlint library (verify by attempting import cfnlint in a throwaway Python command)<resolved-version> from PyPI. Do you want me to install it, or would you prefer to install it manually?”cfn-lint version from PyPI, with no extra packages. If installation is not possible — pip missing, PyPI unreachable, or the user declines — You MUST NOT attempt another cfn-lint installation mechanism. Tell the user that cfn-lint cannot run, note the reduced local validation coverage, and ask whether to use the cloudformation-validate SOP as the alternate local validator or stop.Obtain the CloudFormation template from the user.
Constraints:
Execute cfn-lint against the template using the best available mechanism.
Constraints:
cfn-lint CLI is available, You MUST invoke it on the template file with appropriate flags:
--regions us-east-1 eu-west-1--ignore-checks W2001 E3012--format json for structured outputcfn-lint --format json --regions us-east-1 template.yamlcfnlint library is available, You MUST invoke cfnlint.api.lint(s=template_content, config={"regions": [...], "ignore_checks": [...]})Report validation findings to the user.
Constraints:
MyBucket errors together)Guide the user on what to do after validation.
Constraints:
Follow the shared security guidance when handling templates, outputs, secrets, tools, and installation artifacts.
AWSTemplateFormatVersion: '2010-09-09'
Resources:
MyFunction:
Type: AWS::Lambda::Function
Properties:
FunctionNam: my-function
Runtime: python3.9
Handler: index.handler
Role: arn:aws:iam::123456789012:role/my-function-role
Code:
ZipFile: |
def handler(event, context):
return {'statusCode': 200}Your template has 1 error, 0 warnings, 0 info messages.
**MyFunction (AWS::Lambda::Function):**
- E3002 at line 6: Invalid Property Resources/MyFunction/Properties/FunctionNam
Fix (line 6):
FunctionName: my-function # Typo: FunctionNam → FunctionNameIf the tool or CLI returns a parsing error, the template has invalid YAML or JSON syntax. Check for indentation issues, missing colons, or unquoted special characters. Fix the syntax and re-run validation.
If cfn-lint reports errors you believe are incorrect, suppress specific rules using ignore_checks. Verify the rule ID from the output (e.g., W2001) and pass it in the parameter.
Some resource properties are only valid in certain regions. If you see region-related errors, pass the target deployment region in the regions parameter to get accurate validation.
Resolve a compatible cfn-lint release from the official installation documentation and authoritative PyPI metadata, then install that exact user-approved version. Do not encode a version range in this SOP. If installation is not possible (pip missing, PyPI unreachable, or the user declines), do not try another cfn-lint installation mechanism. Ask whether to use the cloudformation-validate SOP as the alternate local validator or stop. Never report the template as locally validated when no local validator ran.