aws-sam-cli icon indicating copy to clipboard operation
aws-sam-cli copied to clipboard

Sam validate always returns Valid!

Open ollyjshaw opened this issue 9 years ago • 6 comments

The tool sam validate is supposed to report errors when a SAM template is not valid.

Currently, it reports anything as valid.

steps to reproduce

cat "{}" > test.json sam validate -t test.json

Expected - Some validation message Actual - Valid!

Affects version

  • snapshot local
  • 0.2.2

ollyjshaw avatar Nov 28 '17 17:11 ollyjshaw

I think validate tests if your resources are valid (setup with correct values). Not necessarily that the template is invalid.

Definitely a nice to have though when it comes to cloudformation validity.

iph avatar Dec 02 '17 02:12 iph

@iph It also fails for the example given in the readme https://github.com/awslabs/aws-sam-local#validate-sam-templates

I had a look a the tests, the seem to be a bit happy path focused. I've got no Go experience, but I'll have a look to see if I can describe this in a test.

ollyjshaw avatar Dec 05 '17 19:12 ollyjshaw

Currently sam validate just checks whether the template is valid JSON/YAML.

At initial launch, we did do further validation against the SAM specification, however the implementation had a few major bugs and caused a lot of problems for people. As such, we removed this functionality until it can be revisited.

We've recently done some work in the goformation to automatically generate a JSON Schema for the whole CloudFormation and SAM specification - which I think we could use within SAM Local to do this more advanced validation.

PaulMaddox avatar Dec 05 '17 19:12 PaulMaddox

Thanks for the insight @PaulMaddox. That sounds like it will be really great. We were hoping to use it in our build pipeline to validate nice and early. We're currently doing some validation with aws cloudformation validate-template. I think the docs need updating to reflect the information you've provided. I'll get a PR together and you can use as a starting point if you like.

ollyjshaw avatar Dec 05 '17 19:12 ollyjshaw

Great. In the meantime, there's nothing stopping you from using the JSON Schema file I linked to earlier, with a CLI based JSON Schema validator in your buid pipeline. Google shows quite a few options.

PaulMaddox avatar Dec 05 '17 19:12 PaulMaddox

I made a Ruby script that will read the YAML into JSON and validate against the schema if anyone is interested. https://gist.github.com/metaskills/674d819f24f41ddb9664b0386d147ce0

metaskills avatar Dec 28 '17 00:12 metaskills