91

I am trying to validate an AWS example CloudFormation template using a command like:

▶ aws cloudformation validate-template --template-body template.yml

This leads to the following error message:

An error occurred (ValidationError) when calling the ValidateTemplate operation:
  Template format error: unsupported structure. 

I tried this on many templates, including example templates from the AWS documentation. So I know the templates are okay.

What am I doing wrong?

Alex Harvey
  • 14,494
  • 5
  • 61
  • 97
bgenchel
  • 3,739
  • 4
  • 19
  • 28
  • 13
    To the close voters... This question obviously is not off-topic for SO. AWS CloudFormation is a tool used by developers for deploying apps in the cloud; e.g. Serverless apps on Amazon; AWS CFN is a declarative DSL with programming features; SF people without programming knowledge could not answer this question and would have no use for it. – Alex Harvey Mar 27 '19 at 09:24
  • 1
    Does this answer your question? [Aws cloudformation validate-template keeps giving error (Template format error)](https://stackoverflow.com/questions/25881358/aws-cloudformation-validate-template-keeps-giving-error-template-format-error) – Nae Oct 01 '21 at 07:14

3 Answers3

198

Apparently, the very unhelpful error message comes as a result of improper formatting in the CLI command.

The --template-body argument must be specified as a file URI.

Thus, the correct, runnable form of the command above is:

▶ aws cloudformation validate-template --template-body file://template.yml

See this blog post for more information.

Alex Harvey
  • 14,494
  • 5
  • 61
  • 97
bgenchel
  • 3,739
  • 4
  • 19
  • 28
  • 1
    the error sys that the string "hellobucket.yml" is not a proper cloudformation template which is true ;) – hellomichibye Feb 02 '17 at 07:05
  • 5
    My test shows that relative path to file works from the command line, as long as `file://` is included – Jon Jun 16 '17 at 18:34
  • 4
    A little clarification for future readers... The `--template-body` CLI parameter takes a `string` argument, i.e., the template as a string. Using the `file://` allows a local file to be supplied instead of the string. – Les Oct 21 '20 at 12:51
  • If that is assumed to be one uri, then it would be better to show the assumed schema in the error message, that way if I see "http:// template.yml" i know that I need to change http: by file: – yucer Feb 23 '21 at 15:37
  • 3
    I wouldn't be able to figure this out without this answer! You have a special place in haven... – Benjamin May 17 '21 at 16:41
  • Same comments as @Benjamin .. You saved my day. AWS should really improve this error message. I wrote my template all over again and was still getting the error. – Vishal Jun 11 '21 at 17:02
  • Thank you for this! I didn't realize my tab-complete had automatically appended another `file:` prefix to the argument. – richid Aug 24 '22 at 18:14
5

In case, you are using windows file system, you can use like this:

--template-body file://c:/Windows/myfile.json

or

--template-body file://localhost/c$/Windows/myfile.json
Nae
  • 14,209
  • 7
  • 52
  • 79
jelongpark
  • 144
  • 1
  • 6
0
` aws cloudformation create-stack --region us-east-1 \
 --stack-name c3-app -\
 -template-body file:..//starter/c3-app.yml \
 --capabilities CAPABILITY_IAM
`

the template-body must specified with file:"destination of the file from location you are now"