Skip to content
Latchkey

Serverless Framework "The CloudFormation template is invalid" in CI

Serverless Framework synthesizes a CloudFormation template from serverless.yml and CloudFormation rejected it at validation. The message names the invalid part: an unresolved reference, an unknown property, or a malformed resource.

What this error means

serverless deploy fails with "Serverless Error ... The CloudFormation template is invalid" plus a ValidationError detail like "Template format error" or "Unresolved resource dependencies".

serverless
Error:
The CloudFormation template is invalid: Template error: instance of Fn::GetAtt
references undefined resource MyQueue

Common causes

A reference to a resource that does not exist

A Ref/Fn::GetAtt in resources: or a function event points at a logical id that is not defined, so validation fails.

An invalid property or type in serverless.yml

A misspelled property, wrong type, or unsupported value produces a template CloudFormation cannot parse.

How to fix it

Read the validation detail and fix the reference

  1. Read the named undefined resource or invalid property.
  2. Define the missing logical id or correct the property.
  3. Re-package locally to confirm a valid template before deploy.
Terminal
serverless package
# inspect .serverless/cloudformation-template-update-stack.json

Print and inspect the generated template

Use the print command to see the resolved config that produced the template.

Terminal
serverless print

How to prevent it

  • Package locally before deploying to catch template errors early.
  • Reference only logical ids you actually define.
  • Validate property names against the resource schema.

Frequently asked questions

What causes ""The CloudFormation template is invalid""?
A Ref/Fn::GetAtt in resources: or a function event points at a logical id that is not defined, so validation fails.
How do I fix "The CloudFormation template is invalid"?
Read the validation detail and fix the reference

Related guides

References

Latchkey auto-heals failures like this one - detected, fixed, and retried without you. Start free → 30-day trial · No credit card