无服务器错误 - 没有文件匹配包含/排除模式

问题描述

我正在尝试使用 python 进行一些骨架部署。这是我的 serverless.yaml

我的文件夹结构是

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

这很好用。现在只要我添加一个图层,就会出现以下错误

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

我还尝试添加包含和排除模式。但这并没有解决我的问题

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:
        - ./**

我也尝试过非常具体

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

解决方法

我遇到了同样的问题并找到了这个答案here

serverless 正在根据根包中指定的模式检查这些文件:exclude 并且因为 ./** 匹配每个文件并且包含模式 ./functions/**/* 匹配 none,实际上没有文件包含在层,导致错误。

只需尝试从排除项中删除 ./**

package:
  individually: true
  exclude: 
    - ./** # <-- remove this!