【问题标题】:Add multiple properties to serverless.yaml with one line?用一行向 serverless.yaml 添加多个属性?
【发布时间】:2022-02-11 03:06:29
【问题描述】:

我们有许多无服务器服务。他们中的许多人共享一些属性。以下是他们分享的部分内容:

// shared.yaml

frameworkVersion: '3'
configValidationMode: error

plugins:
  modules:
    - serverless-prune-plugin
    - serverless-deployment-bucket

custom:
  sharedHost: ${file(./shared-host.config.js)}
  prune:
    automatic: true
    number: 2

  Outputs:
    UserInformation:
      Value: ${self:custom.sharedHost.userId}
      Description: ${self:custom.sharedHost.userArn}

    GitInformation:
      Value: ${self:custom.sharedHost.gitId}
      Description: ${self:custom.sharedHost.gitDescription}

是否可以用一行将这些属性添加到serverless.yaml 文件中?

我正在寻找类似的东西:

// services/some-service/serverless.yaml

service: SomeService
join: ${file(../../shared.yaml)}

custom:
  someProp: someValue

我在问题中添加了json 标签,因为我认为如果使用无服务器或 yaml 功能无法做到这一点,那么也许可以使用一些 json 功能。

【问题讨论】:

    标签: json yaml serverless-framework


    【解决方案1】:

    我知道在 serverless.yml 文件中,您可以像这样在一行中从外部文件导入环境变量

    environment: ${file(env.yml):${self:provider.stage}, file(env.yml):default}
    

    如果你使用 node js,你可以拥有 serverless.ts 或 serverless.js 并使用 Object.assign 轻松导入文件

    resources: {
        Resources: Object.assign(dynamodbTables, gatewayDomain, gatewayAuthorizer),
      }
    

    示例:https://github.com/TheSmartMonkey/serverless/blob/main/reports-service/serverless.ts

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-08-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多