Multiple serverless files sharing the same api gateway

懵懂的女人 提交于 2019-12-07 01:00:28

问题


I am using serverless framework to build a REST API. I have reached the 200 limit stack size and read about the multiple approaches to circumvent it. The most common approach is to split the stacks in a "microservices fashion", where each stack handles a particular set of resources that make sense together.

Because of how serverless works each of those services would create a new api gateway for itself and then, as explained in this blog post, a shared domain can be setup between them so all endpoints can be accessed through the same base url.

Even though this is a valid solution I would really like to be able to work with a single API gateway resource shared between the different stacks, so I don't have to decide upfront a separation of concerns between the different components of my api. Is this possible?


回答1:


This feature has been recently added to serverless. Documentation is available here.

Essentially the apiGateway to be used in a serverless file can be configured through a config option inside "providers".

provider: 
  ...
  apiGateway:
    restApiId: xxxxxxxxxx # REST API resource ID. Default is generated by the framework
    restApiRootResourceId: xxxxxxxxxx # Root resource, represent as / path

This feature was introduced by this pull request and is available from serverless version 1.26.



来源:https://stackoverflow.com/questions/48773229/multiple-serverless-files-sharing-the-same-api-gateway

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!