无服务器框架和条件值的解决方法
Serverless framework and workaround for conditional value
阅读 Serverless 文档及其论坛中的一些帖子后,我注意到无法实现明确的条件归因。
我想根据舞台设置一个或多个值。
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
我找到了一些 libraries/plugins,比如 https://www.serverless.com/plugins/serverless-plugin-ifelse,但大多数都已经过时了。
您是否知道无需安装插件即可实现此目的的解决方法?
一种常用的解决方法是定义每个阶段的值并使用变量解析路由到特定的值。
custom:
stageTargets:
dev:
domain: dev.foobar.com
prod:
domain: foobar.com
target: ${self:custom.stageTargets.${self:custom.stage}}
domain: ${self:custom.target.domain}
阅读 Serverless 文档及其论坛中的一些帖子后,我注意到无法实现明确的条件归因。
我想根据舞台设置一个或多个值。
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
我找到了一些 libraries/plugins,比如 https://www.serverless.com/plugins/serverless-plugin-ifelse,但大多数都已经过时了。
您是否知道无需安装插件即可实现此目的的解决方法?
一种常用的解决方法是定义每个阶段的值并使用变量解析路由到特定的值。
custom:
stageTargets:
dev:
domain: dev.foobar.com
prod:
domain: foobar.com
target: ${self:custom.stageTargets.${self:custom.stage}}
domain: ${self:custom.target.domain}