是否可以使用 Serverless 在两个区域部署 API Gateway 和 Lambda?
Is it possible to deploy API Gateway and Lambda in two regions with Serverless?
我正在使用 serverless 通过 AWS 上的 API 网关部署我的 Lambda APIs,但看起来缺少的一件事是部署 Lambda API 和 API 网关进入不同的区域。现在,如果我将区域设置为 serverless deploy
命令,它会在该区域中部署这两个区域,而不管我在 serverless.yml
文件中为 Lambda 指定了不同的区域。假设您有这个文件:
service: My-Awesome-API
provider:
name: aws
region: eu-west-1
runtime: nodejs12.x
memorySize: 384
functions:
graphql:
handler: src/index.handler
name: My-Awesome-GraphQL-API
events:
- http:
path: graphql
method: POST
cors: true
- http:
path: graphql
method: GET
cors: true
然后使用此命令 serverless deploy --region=eu-central-1
部署 API。
Lambda 函数将部署在 eu-central-1
而不是 eu-west-1
.
既然这很有用,而且可以在 API 网关内完成,是否也可以通过无服务器框架指定此行为?
提供商设置中的区域只是默认区域。通过使用 --region
参数,您可以覆盖该默认值,因此该行为是预期的。
无服务器基于 CloudFormation in the background and CloudFormation stacks 特定于区域,因此在普通 CloudFormation 中无法跨多个区域在单个堆栈中部署资源。
(尽管您可以使用自定义资源来做到这一点,但我建议您不要这样做,除了少数极端情况。)
我正在使用 serverless 通过 AWS 上的 API 网关部署我的 Lambda APIs,但看起来缺少的一件事是部署 Lambda API 和 API 网关进入不同的区域。现在,如果我将区域设置为 serverless deploy
命令,它会在该区域中部署这两个区域,而不管我在 serverless.yml
文件中为 Lambda 指定了不同的区域。假设您有这个文件:
service: My-Awesome-API
provider:
name: aws
region: eu-west-1
runtime: nodejs12.x
memorySize: 384
functions:
graphql:
handler: src/index.handler
name: My-Awesome-GraphQL-API
events:
- http:
path: graphql
method: POST
cors: true
- http:
path: graphql
method: GET
cors: true
然后使用此命令 serverless deploy --region=eu-central-1
部署 API。
Lambda 函数将部署在 eu-central-1
而不是 eu-west-1
.
既然这很有用,而且可以在 API 网关内完成,是否也可以通过无服务器框架指定此行为?
提供商设置中的区域只是默认区域。通过使用 --region
参数,您可以覆盖该默认值,因此该行为是预期的。
无服务器基于 CloudFormation in the background and CloudFormation stacks 特定于区域,因此在普通 CloudFormation 中无法跨多个区域在单个堆栈中部署资源。
(尽管您可以使用自定义资源来做到这一点,但我建议您不要这样做,除了少数极端情况。)