简体   繁体   English

是否可以使用 Serverless 在两个区域部署 API 网关和 Lambda?

[英]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.

相关问题 无服务器 Lambda 和 API 网关的 CORS 问题 - CORS issues with Serverless Lambda and API Gateway Serverless API Gateway/Lambda 下载失败 PDF - Serverless API Gateway/Lambda fails to download PDF Terraform 无服务器应用程序与 AWS Lambda 和 API 网关未知令牌? - Terraform Serverless Applications with AWS Lambda and API Gateway unknown token? GCP 上的无服务器 API 网关 - Serverless API Gateway on GCP Django 在无服务器上运行的应用程序 + Lambda + API 网关 HTTP API 正在重写链接以使用默认前缀 - Django application running on top of Serverless + Lambda + API Gateway HTTP API is rewriting links to be prefixed with default 是否可以从 AWS 无服务器 API 中的其他 lambda 函数调用 lambda function? - Is it possible to call lambda function from other lambda functions in AWS serverless API? api网关和lambda分页 - api gateway and lambda pagination 如何使用 Serverless Framework 在多个区域部署堆栈? - how to deploy a stack in multiple regions using the Serverless Framework? AWS Cloudformation Lambda + API 网关 V2:无法部署 API,因为此 API 中不存在路由 - AWS Cloudformation Lambda + API Gateway V2: Unable to deploy API because no routes exist in this API 如何使用无服务器框架通过 AWS API 网关在 Node.js 中编写的 AWS Lambda function 上返回错误? - How do I return errors on an AWS Lambda function written in Node.js through the AWS API Gateway using the Serverless framework?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM