Skip to content

sam validate breaks when using Auth block under AWS::Serverless::Api #1074

Closed

Description

@terlar

Description

When having a template.yaml including an Auth property under AWS::Serverless::Api it is invalid with a very confusing error message. If I remove this configuration the sam validate command validates properly.

Steps to reproduce

A template.yaml including:

  ...
  BaseApi:
    Type: AWS::Serverless::Api
    Properties:
      StageName: Prod
      Auth:
        DefaultAuthorizer: MyAuthorizer
        Authorizers:
          MyAuthorizer:
            FunctionArn: !GetAtt MyAuthFunction.Arn
            Identity:
              Header: Authorization
              ValidationExpression: Bearer .*
              ReauthorizeEvery: 299 # Seconds

  MyAuthFunction:
    Type: AWS::Serverless::Function
    Properties:
      CodeUri: build/
      Handler: myAuthorizer.handler
  ...

Observed result

I skipped the --debug flag as it might include some sensitive information and I didn't see any valuable output there.

With Auth config:

$ sam validate
Template provided at '/var/opt/template.yaml' was invalid SAM Template.
Error:  

Without Auth config:

$ sam validate
/var/opt/template.yaml is a valid SAM Template

Expected result

The template would be valid even with an Auth section defined.

Additional environment details (Ex: Windows, Mac, Amazon Linux etc)

  1. OS: Linux
  2. sam --version: 0.13.0

Activity

  1. jfuss commented on Mar 22, 2019

    @jfuss
    Contributor

    @terlar This is an error with your template. I get [InvalidResourceException('BaseApi', "Auth works only with inline Swagger specified in 'DefinitionBody' property")] ('BaseApi', "Auth works only with inline Swagger specified in 'DefinitionBody' property") when I run validate with the above template.

    Side note: You should install in Python3.6+ so you can see the errors with validate instead of the Error: with no additional details.

    Closing as the definition is not correct and validate is working as expected.

    Update:
    This is actually a duplicate of #803

  2. terlar commented on Mar 22, 2019

    @terlar
    Author

    Interesting, because I have successfully deployed this template and are using the Auth block. Thank you for the feedback regarding Python 3.6+ I wasn't aware. I will investigate further.

  3. terlar commented on Mar 22, 2019

    @terlar
    Author

    I now see errors with python 3, and it makes sense. Is it planned to have support for Auth without using inline Swagger? And perhaps the most interesting is it unintentional that it actually works when you do it this way?

  4. terlar commented on Mar 22, 2019

    @terlar
    Author

    Seems like this has been discovered before:

    It is supported by SAM and thus works with the sam package/deploy, but not the sam validate. I still believe it should be fixed in the validator.

  5. terlar commented on Mar 22, 2019

    @terlar
    Author

    However there is already a ticket for it: #803

  6. jfuss commented on Mar 22, 2019

    @jfuss
    Contributor

    Ahh. It's that...

    Yes this should be fixed in our validate command. Would you be up for submitting a patch for it? I think our check here needs a small adjustment, plus updating/new tests.

  7. terlar commented on Mar 22, 2019

    @terlar
    Author

    Thanks for providing the hints where to look, I might be able to do it. If I don't manage to do it today, it will take at least another week until I can take a look at it. But I will give it a shot.

  8. jackmcguire1 commented on Apr 27, 2019

    @jackmcguire1

    Any progress on this?

  9. piersf commented on Apr 27, 2020

    @piersf

    Was there a solution to this? I got the same error today:

    Error: [InvalidResourceException(ManagementApi', "Invalid value for 'Auth' property")] ('ManagementApi', "Invalid value for 'Auth' property")

    In my case, the issue appears when i add UsagePlan under the Auth object.

    I am using SAM CLI, version 0.41.0 and Python 3.7.4

    sam deploy works fine, however

    Adding swagger: 2.0 under DefinitionBody as mentioned in #803 (comment) does not fix anything.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions