如何在serverless中添加httpapi阶段



我正在尝试将无服务器应用程序部署到不同阶段(prod和dev(。我想将其部署到两个不同阶段的单个API网关比如:-http://vfdfdf.execute-api.us-west-1.amazonaws.com/dev/http://vfdfdf.execute-api.us-west-1.amazonaws.com/prod/

我用无服务器写了一段代码

provider:
name: aws
runtime: nodejs14.x
region: ${self:custom.${self:custom.stage}.lambdaRegion}
httpApi: 
id: ${self:custom.${self:custom.stage}.httpAPIID}
stage: ${opt:stage, 'dev'}

编辑以反映评论

这可以在无服务器部署阶段完成。

默认情况下,我只会在无服务器yml文件中有dev

provider:
name: aws
runtime: nodejs14.x
stage: dev
region: eu-west-1
httpApi:
# Attach to an externally created HTTP API via its ID:
id: w6axy3bxdj
# or commented on the very first deployment so serverless creates the HTTP API
custom:
stage: ${opt:stage, self:provider.stage}
functions:
hello:
handler: handler.hello
events:
- httpApi:
path: /${self:custom.stage}/hello
method: get

然后,命令:

serverless deploy

部署在阶段CCD_ 3和此处的区域CCD_。它使用默认值。

endpoint: GET - https://w6axy3bxdj.execute-api.eu-west-1.amazonaws.com/dev/hello

而对于生产,可以在命令行上覆盖默认值。然后我会使用命令:

serverless deploy --stage prod

endpoint: GET - https://w6axy3bxdj.execute-api.eu-west-1.amazonaws.com/prod/hello

根据我的理解,您不会更改devprod之间的区域;但如果你想那样做的话。生产部署可以是:

serverless deploy --stage prod --region eu-west-2

部署在与无服务器yml文件中的默认区域不同的区域中。

最新更新