如何将多个serverless.yml文件合并为一个单独的serverless.yml文件?

7
我阅读了这份文档:https://serverless.com/framework/docs/providers/google/guide/services/
users/
  serverless.yml # Contains 4 functions that do Users CRUD operations and the Users database
posts/
  serverless.yml # Contains 4 functions that do Posts CRUD operations and the Posts database
comments/
  serverless.yml # Contains 4 functions that do Comments CRUD operations and the Comments database

如何将这些 serverless.yml 文件合并成单个 serverless.yml 文件?除了部署每个服务外,我还可以运行 serverless deploy 一次来部署所有服务。

2个回答

18

我正在单独的serverless.yml文件中定义函数,并在主serverless.yml文件的functions下包含文件引用,这对我很有效。我还将各个yml文件命名为post-sls.yml、user-sls.yml等。

# foo-functions.yml
getFoo:
  handler: handler.foo
deleteFoo:
  handler: handler.foo

# serverless.yml
---
functions:
  - ${file(../foo-functions.yml)}
  - ${file(../bar-functions.yml)}

参考链接:

https://github.com/serverless/serverless/issues/4218 https://serverless.com/framework/docs/providers/aws/guide/functions/


0

最简单的方法是使用插件(例如这个:https://github.com/economysizegeek/serverless-dir-config-plugin

如果你想要更多的控制,也可以自己动手。例如,你可以将函数特定的配置放在每个目录中,然后使用像cat这样的工具将它们与项目的公共配置文件合并(例如:cat serverless.common.yml users/serverless.yml posts/serverless.yml comments/serverless.yml > serverless.yml)。虽然如果你想合并键等内容,可能需要编写更复杂的代码。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接