Serverless Typescript 插件将我所有的 lambda 函数打包到一个 zip 存档中

Serverless Typescript plugin packs all my lambda functions into one zip archive

下面是我的serverless.yml


service: serverless-typescript-example
provider:
  name: aws

package:
  individually: true

plugins:
  - serverless-plugin-typescript

functions: 
  hello1:
    handler: hello1/src/index.handler
  hello2:
    handler: hello/src/index.handler

我的文件夹结构如下所示

hello1
 --index.ts
 --package.json
hello2
 --index.ts
 --package.json
package.json
serverless.yml

当我 运行 sls 打包时,它会在 .serverless 文件夹中创建 2 个 zip 存档,名称为 hello1.zip 和 hello2.zip。解压缩后,两个文件夹具有相同的内容,即 hello1 ande hello2 与 node_modules.

是否有任何选项可以解决此问题,我们能否将 .zip 文件放在相应的函数文件夹中,我的意思是 hello1.zip 在 hello1 和 hello2.zip 在 hello2

我没用过 serverless-plugin-typescript,但我们用过 serverless-webpack,它做得非常好。由于使用 webpack 打包,它大大减少了 lambda 的大小。

还有一个使用 serverless-webpack 插件的无服务器创建模板。

serverless create --template aws-nodejs-typescript

zip 文件默认放置在 .serverless 文件夹中。您可以使用以下命令指定目标文件夹。我认为没有办法为每个入口点定义不同的目的地。

serverless package --package my-artifacts