【问题标题】:How to combine multiple serverless.yml files to single serverless.yml file?如何将多个 serverless.yml 文件合并为单个 serverless.yml 文件?
【发布时间】:2019-03-14 00:45:41
【问题描述】:

我读过这个文档: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 来部署所有服务。

【问题讨论】:

    标签: serverless-framework


    【解决方案1】:

    我在单个 serverless.yml 文件中定义函数,并在主 serverless.yml 文件中的函数下包含文件引用,它适用于我,我还将单个 yml 文件命名为 post-sls.yml、users-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/

    【讨论】:

      【解决方案2】:

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

      如果您想要更多控制权,您也可以自己动手。例如,您可以将特定功能的配置放在每个目录中,然后使用cat 之类的工具将它们与项目的通用配置(例如cat serverless.common.yml users/serverless.yml posts/serverless.yml comments/serverless.yml > serverless.yml)连接起来。虽然如果你想将键 &c 合并在一起,你可能需要编写更复杂的东西。

      【讨论】:

        猜你喜欢
        • 2021-07-29
        • 2021-04-16
        • 2020-07-11
        • 1970-01-01
        • 2020-08-30
        • 2012-06-23
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多