本文介绍了如何在无服务器框架中创建多个阶段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在无服务器中创建多个阶段,但没有成功.

i'm trying yo create multiple stages in serverless with no success.

这是我的serverless.yml:

service: some-cache-updater
provider:
  name: aws
  runtime: nodejs8.10
  stage: dev

functions:
  scheduledUpdater:
    handler: handler.scheduledUpdater
    timeout: 120

我想添加的是一个具有不同超时的 prod 阶段.

What i wish to add is a prod stage with a different timeout.

我可以在同一个 yml 中完成吗?

Can i do it in the same yml?

任何示例或参考资料都会有所帮助...谢谢.

Any way an example or a reference will be helpful... thanks.

推荐答案

Use Serverless' $self 参考插值,可以包括进一步的插值.

Use Serverless' $self reference interpolation which can include further interpolation.

在必要时定义自定义变量.如果变量不存在,您也可以使用默认值.

Define a custom variable where necessary. You can also use a default value if the variable doesn't exist.

示例:

service: some-cache-updater

custom:
  functimeout:
    prod: 120
    uat: 60

provider:
    name: aws
    runtime: nodejs8.10
    stage: ${opt:stage, 'dev'}

functions:
    scheduledUpdater:
    handler: handler.scheduledUpdater
    # Lookup stage key from custom.functimeout. If it doesn't exist
    # default to 10
    timeout: ${self:custom.functimeout.${self:provider.stage}, '10'}

然后,当您部署时,您可以传递 --stage prod--stage uat 参数.在这个例子中,没有设置舞台将默认为 dev

Then, when you deploy you can pass the --stage prod or --stage uat argument. In this example, no setting the stage will default to dev

这篇关于如何在无服务器框架中创建多个阶段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-29 20:11
查看更多