How to share a single API Gateway across multiple SAM templates?
M

0

7

I've been trying to use a single APIGateway across multiple SAM templates. For this, I've tried importing the RestApiId from the base template on other SAM templates and use it under the event sections of a lambda. But SAM has restriction saying that

RestApiId must be a valid reference to an '''AWS::Serverless::Api''' resource in same template.

After 3 hours of research, I get to know that we can achieve it by defining the API gateway in the base template and create Role/Policies/Definitions such that it is allowed to invoke required functions. Split Lambdas into multiple Lambda-only SAM files but without any Api type Event defined under it. In this way, it's possible to create our Lambdas and API Gateway independent of each other and integrate using Swagger/OpenAPI and arrange for permissions separately.

Below are the useful links which recommended the above approach.

Link1

Link2

I feel this approach a little complex & this might exceed the CFN 200 limit on the base template if the APIs are getting more on the swagger file. I would appreciate if someone suggested a simpler way to import the apiGateway across different templates.

Monoculture answered 11/2, 2021 at 10:3 Comment(1)
Did you solve this? Which way did you choose to go?Bevin

© 2022 - 2024 — McMap. All rights reserved.