2

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?

1 Answer 1

1

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.