Search code examples
amazon-web-servicesaws-api-gatewayserverless

No files match include/exclude patterns when deploying API Gateway with mock integration


I want to deploy a APIGateway with mock integration for testing via serverless using this example.

However when I try to deploy it I get the following error:

No file matches include / exclude patterns

Which I don't understand because I don't want to include or exclude anything. I just wanna create the Gateway with mock integration which should give me an endpoint which returns a specific response. I don't want to deploy any lambda. Here is the full serverless:

service: sls-apig
provider:
  name: aws
functions:
  hello:
    handler: handler.hello
    events:
      - http:
          path: hello
          cors: true
          method: get
          integration: mock
          request:
            template:
              application/json: '{"statusCode": 200}'
          response:
            template: $input.path('$')
            statusCodes:
              201:
                pattern: ''

Solution

  • The error normally occurs when you are testing the Serverless Framework in a directory with only the serverless.yml file. This looks like a bug with the Serverless Framework.

    Your project structure must be like the following:

    project
    ├── .serverless/
    ├── serverless.yml
    

    To stop this error we only need to add a file on this directory, in the following example I am adding the foo.txt file:

    project
    ├── .serverless/
    ├── foo.txt
    ├── serverless.yml
    

    And the error No file matches include / exclude patterns will stop to happen.

    Also, we can use this file as the template of the response using the following code:

    response:
      template: ${file(foo.txt)}
      statusCodes:
        201:
          pattern: ''