

Deploying multiple Serverless Framework apis to the same AWS API Gateway
source link: https://www.kevinhooke.com/2021/10/24/deploying-multiple-serverless-framework-apis-to-the-same-aws-api-gateway/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Deploying multiple Serverless Framework apis to the same AWS API Gateway
By default, each Serverless project you deploy will create a new API Gateway. In most cases this works fine, but for larger projects you may need to split your apis across multiple smaller Serverless projects, each with their own serverless.yml that can be deployed independently.
The Serverless docs describe how to do this here. In each additional Serverless project where you want to add additional apis to an existing API Gateway, you need to specify 2 additional properties in your Serverless.yml, apiGateway and restApiRootResourceId:
provider: name: aws apiGateway: restApiId: xxxxxxxxxx # REST API resource ID. Default is generated by the framework restApiRootResourceId: xxxxxxxxxx # Root resource, represent as / path
apiGateway – this is the 11 character id for your API Gateway that you want to add resources to. You can get this from the console and it’s the prefix in your api gw url, e.g. https://aaaaaaaaaaa.execute-api.us-west-1.amazonaws.com/dev
The id for the root resource is where in your api path structure you want to add your new resource to, either the id of the root / or one of the existing paths beneath the root.
This id value I don’t think is visible in the console, but you can get it a list of all the resources in your API Gateway including the ids of each of the existing resources, with:
aws apigateway get-resources --rest-api-id aaaaaaaaaaa --region us-west-2
It will give a response that looks like:
{ "items": [ { "id": "bbbbbb", "parentId": "aaaaaaaaaa", "pathPart": "example1", "path": "/example1", "resourceMethods": { "GET": {} } }, { "id": "aaaaaaaaaa", "path": "/" } ] }
In this example I have a root / with id = aaaaaaaaa and a resource bbbbbb for /example1.
In this case if I pass aaaaaaaaaa as the value for restApiRootResourceId then my new resource will be added to /, or passing bbbbbb it will be added as a resource under /example1
CategoriesKev's BlogTagsaws, lambda, serverless
Leave a Reply Cancel reply
Your email address will not be published. Required fields are marked *
Comment
Name *
Email *
Website
Save my name, email, and website in this browser for the next time I comment.
Notify me of follow-up comments by email.
Notify me of new posts by email.
This site uses Akismet to reduce spam. Learn how your comment data is processed.
Post navigation
Recommend
-
180
README.md
-
10
WTF is Serverless Framework? Is it the same as serverless? (no, it's not) March 03, 2020...
-
6
Conditionally deploying parts of your CloudFormation stack with the Serverless Framework What do you do when you want to customize which resources are deployed via CloudFo...
-
6
Horizon 8.0 Part 10: Deploying the Unified Access Gateway And we’re back…this week with the final part of deploying a Horizon 2006 environment – deploying the Unified Access Gateway to enable remote access to desktops. Be...
-
9
Serverless Framework API Gateway CORS config If you deploy a Serverless Framework Java Lambda to AWS and attempt to call it locally while developing your frontend, you’ll run into a CORS error like this: Access t...
-
5
Deploying changes to individual Lambdas using Serverless Framework I have a serverless project that deploys 2 Lambdas in the same stack: service: example-apis2 provider: name: aws memorySize: 512 region: u...
-
4
Amazon API Gateway for the .NET Developer - How To Build HTTP APIsAmazon API Gateway is a fully managed service that helps developers build and maintain APIs at any scale. The Gateway act as a ‘front door’ to your business data and b...
-
7
Amazon API Gateway - Introduction To Building REST APIsAmazon API Gateway is an AWS service for managing APIs at any scale. REST APIs and HTTP APIs are both RESTful API products offered by API Gateway. While HTTP APIs are designed...
-
6
This post will cover deploying an application using a SPA (Single Page Application) as a front-end, which serving said static content on a Node-based backend - while on the same Linux Node App Service . Prerequisites
-
6
Speeding up APIs with Ricochet for API Gateway 06/23/2023
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK