Aws-sam-cli: sam validate expects DefinitionBody or DefinitionUri to be set

Created on 28 Nov 2018  路  12Comments  路  Source: aws/aws-sam-cli

Description:

Since the Default Definition Body feature, SAM provides a default DefinitionBody if neither a DefinitionBody or DefinitionUri is set on a AWS::Serverless:Api resource.

SAM CLI still expects DefinitionBody or DefinitionUri to be set in the validation workflow as found here. This assumption should be fixed (check for and replace DefinitionUri with a S3 location if it exists, otherwise do nothing).

Steps to reproduce the issue:

  1. run sam validate on https://github.com/awslabs/serverless-application-model/blob/master/examples/2016-10-31/api_cognito_auth/template.yaml

Observed result:

Template provided at '...examples/2016-10-31/api_cognito_auth/template.yaml' was invalid SAM Template.
Error: [InvalidResourceException('MyApi', "Cors works only with inline Swagger specified in 'DefinitionBody' property")] ('MyApi', "Cors works only with inline Swagger specified in 'DefinitionBody' property")

Expected result:
Validation should succeed

Output of sam --version:
0.7.0, 0.8.0, 0.9.0

arevalidate contributorgood-first-issue stagwaiting-for-release

Most helpful comment

Are there any updates? Not being able to run validate and/or cfn-lint really makes automated CI/CD difficult

All 12 comments

Are there any updates? Not being able to run validate and/or cfn-lint really makes automated CI/CD difficult

please someone, work on this <3

Still seeing this with sam 0.16.1 please fix

@jackmcguire1 or @rudpot Either of you want to take a stab at a fix?

yes I have this problem too and this is annoying. Having Cognito in my template, sam validate becomes useless.

Still have this issue, please fix it!

Release in v0.21.0.

Closing

Release in v0.21.0.

Closing

@jfuss 'sam validate' seems to still be broken if using Fn::Transform and AWS::Include to reference and include an OpenAPI definition in a separate file while having a Globals -> Api -> Cors config in the SAM template.

sam --version
SAM CLI, version 0.22.0

SAM template:

Globals:
  Function:
    Runtime: nodejs10.x
    Timeout: 60
  Api:
    Cors:
      AllowOrigin: 
        Fn::Sub: "'${CorsAllowOrigin}'"
      AllowMethods: "'DELETE,GET,HEAD,OPTIONS,PATCH,POST,PUT'"
      AllowHeaders: "'Content-Type,X-Amz-Date,Authorization,X-Api-Key,X-Amz-Security-Token'"

...
      DefinitionBody:
        Fn::Transform:
          Name: AWS::Include
          Parameters:
            Location: ./openapi.yaml
sam validate
Template provided at '<my_path>/template.yaml' was invalid SAM Template.
Error: [InvalidResourceException('MyApi', "Unable to add Cors configuration because 'DefinitionBody' does not contain a valid Swagger")] ('MyApi', "Unable to add Cors configuration because 'DefinitionBody' does not contain a valid Swagger")

If I comment out my global cors config in my SAM template then validation works fine.

@jfuss I'm also experiencing the same issue paulsson-cs is reporting. Anyway we can get this one reopened to address this?

You need to add swagger: 2.0 under DefinitionBody for your API

This still seems to be an issue: https://github.com/awslabs/aws-sam-cli/issues/1074#issuecomment-619857358

I have SAM CLI, version 1.6.2
and I still have this error.

Reopen an fix it please.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

terrywarwar picture terrywarwar  路  26Comments

nicosuave picture nicosuave  路  44Comments

kyeljmd picture kyeljmd  路  31Comments

matheusmaximo picture matheusmaximo  路  30Comments

ztolley picture ztolley  路  28Comments