[英]Is it possible to deploy API Gateway and Lambda in two regions with Serverless?
I'm using serverless to deploy my Lambda APIs through API Gateway on AWS, but one thing that looks like is missing is the ability to deploy the Lambda API and the API Gateway into different regions.我正在使用无服务器通过 AWS 上的 API 网关部署我的 Lambda API,但看起来缺少的一件事是将 Lambda API 和 API 网关部署到不同区域的能力。 Right now, if I set the region to the
serverless deploy
command, it deploys both in that region, regardless of the fact that in the serverless.yml
file I specified a different region for the Lambda.现在,如果我将区域设置为
serverless deploy
命令,它会在该区域中部署这两个区域,而不管我在serverless.yml
文件中为 Lambda 指定了不同的区域。 So let's say you have this file:所以假设你有这个文件:
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
and you deploy the API with this command serverless deploy --region=eu-central-1
.然后使用此命令
serverless deploy --region=eu-central-1
部署 API。 The Lambda function will be deployed in eu-central-1
rather than in eu-west-1
. Lambda 函数将部署在
eu-central-1
而不是eu-west-1
中。
Since this can be useful, and it can be done within API Gateway, is there a way to specify this behaviour with the serverless framework too?由于这很有用,并且可以在 API 网关内完成,是否也有一种方法可以在无服务器框架中指定此行为?
The region in the provider settings is just the default.提供商设置中的区域只是默认设置。 By using the
--region
argument you overwrite that default, so the behaviour is expected.通过使用
--region
参数,您可以覆盖该默认值,因此该行为是预期的。
Serverless is based on CloudFormation in the background and CloudFormation stacks are region-specific so there's no way in vanilla CloudFormation to deploy resources in a single stack across multiple regions. Serverless 在后台基于CloudFormation ,而CloudFormation 堆栈是区域特定的,因此普通 CloudFormation 无法在跨多个区域的单个堆栈中部署资源。
(You can do that with custom resources though, but I would recommend against that practice except from a few edge cases.) (虽然你可以使用自定义资源来做到这一点,但我建议不要这样做,除了少数边缘情况。)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.