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. 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. 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
.
The Lambda function will be deployed in eu-central-1
rather than in 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?
The region in the provider settings is just the default. By using the --region
argument you overwrite that default, so the behaviour is expected.
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.
(You can do that with custom resources though, but I would recommend against that practice except from a few edge cases.)