Serverless error - No file matches include / exclude patterns
Asked Answered
B

1

8

I am trying some skeleton deployment using python. Here is my serverless.yaml

My folder structure is

serverless-test
|_lambdas
|____handler.py
|_layers
|____common
|_________somefunction.py
service: serverless-test

frameworkVersion: '2'

provider:
  name: aws
  runtime: python3.8
  lambdaHashingVersion: 20201221

  stage: test
  region: us-west-2

functions:
  hello:
    handler: lambdas/handler.hello

This works fine. Now as soon as I add a layer, I get the following error

No file matches include / exclude patterns

service: serverless-test

frameworkVersion: '2'

provider:
  name: aws
  runtime: python3.8
  lambdaHashingVersion: 20201221

  stage: test
  region: us-west-2

functions:
  hello:
    handler: lambdas/handler.hello
    layers:
      - {Ref: CommonLambdaLayer}

layers:
  common:
    path: layers/common
    name: common-module
    description: common set of functions

I also tried adding include and exclude patterns. But it didn't solve my problem

service: serverless-test

frameworkVersion: '2'

provider:
  name: aws
  runtime: python3.8
  lambdaHashingVersion: 20201221

  stage: test
  region: us-west-2

package:
  individually: true
  exclude: 
    - ./**
  include:
    - ./lambdas/**

functions:
  hello:
    handler: lambdas/handler.hello
    layers:
      - {Ref: CommonLambdaLayer}

layers:
  common:
    path: layers/common
    name: common-module
    description: common set of functions
    package:
      include:
        - ./**

I also tried being very specific

service: serverless-test

frameworkVersion: '2'

provider:
  name: aws
  runtime: python3.8
  lambdaHashingVersion: 20201221

  stage: test
  region: us-west-2

package:
  individually: true
  exclude: 
    - ./**

functions:
  hello:
    handler: lambdas/handler.hello
    layers:
      - {Ref: CommonLambdaLayer}
    package:
      exclude:
        - ./**
      include:
        - ./lambdas/handler.py

layers:
  common:
    path: layers/common
    name: common-module
    description: common set of functions
    package:
      exclude:
        - ./**
      include:
        - ./layers/common/somefunction.py
Barbbarba answered 1/2, 2021 at 22:40 Comment(0)
D
14

I had the same issue and found this answer here:

serverless is checking those files against the patterns specified in the root package:exclude and because./** matches every file and the include-pattern./functions/**/* matches none, no files are actually included in the layer, which causes the error.

Just try removing the ./** from the excludes:

package:
  individually: true
  exclude: 
    - ./** # <-- remove this!
Dioptrics answered 5/2, 2021 at 12:41 Comment(1)
I changed ./** to ./*. Now, it is workingTechnique

© 2022 - 2024 — McMap. All rights reserved.