Reputation: 88317
I used AWS SAM to generate my Lambda/APIs. But I want to be able to get this RestApi so I can use it in another SAM template.
The idea is to have 1 base infra CloudFormation/SAM template that creates the network, ALB, API Gateway things
Then each "micro-service" will have its own SAM template and it will create API endpoints referencing this "root" RestApi by specifying the RestApiId
attribute
Is this a correct approach? Wonder if when I deploy each service, will it remove the APIs for the other services?
Upvotes: 2
Views: 524
Reputation: 193
You can access default auto generated RestApi as ServerlessRestApi
. This is logical resource id for auto generated RestApi resource.
ServerlessRestApi
access example in template.yaml
is as follows.
Outputs:
ApiRootURL:
Description: API Root URL
Value: !Sub "https://${ServerlessRestApi}.execute-api.${AWS::Region}.amazonaws.com/${ServerlessRestApi.Stage}"
You can see ServerlessRestApi
in the resource list of you CloudFormation stack. ServerlessRestApi
is not documented, so it might be changed in the future version.
Upvotes: 1