【问题标题】:Serverless framework and workaround for conditional value无服务器框架和条件值的解决方法
【发布时间】:2020-07-21 17:38:20
【问题描述】:

在阅读了无服务器文档和他们论坛中的一些帖子后,我注意到没有办法实现明确的条件归因。

我想根据阶段设置一个或其他值。

provider:
  stage: ${opt:stage, 'production'}

custom:
  domain: here's where the conditional should set one or the other value

所以,如果是生产阶段 custom.domain 应该保存值:www.mydomain.com,但如果是开发阶段,它应该保存 www-dev.mydomain.com

我发现了一些库/插件,例如 https://www.serverless.com/plugins/serverless-plugin-ifelse,但其中大部分都已过时。

您知道无需安装插件即可实现此目的的解决方法吗?

【问题讨论】:

    标签: serverless-framework serverless


    【解决方案1】:

    一种常用的解决方法是定义每个阶段的值并使用可变分辨率路由到特定的值。

    custom:
      stageTargets:
        dev:
          domain: dev.foobar.com
        prod:
          domain: foobar.com
      target: ${self:custom.stageTargets.${self:custom.stage}}
      domain: ${self:custom.target.domain}
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-02-25
      • 1970-01-01
      • 2022-01-22
      • 2022-08-05
      • 2018-11-23
      • 1970-01-01
      • 2020-10-01
      • 1970-01-01
      相关资源
      最近更新 更多