How do I configure serverless.yml to put my serverless functions under an already existing RestAPI with a custom domain (api.example.com). By default serverless creates a new API for each serverless.yml.
you’re correct that each
serverless.yml will create a new RestAPI resource in API Gateway. You can then map multiple RestAPIs to the same custom domain using a BasePathMapping. If you do this, each Rest API must have a base path mapping.
Thus, if you had two services,
products-service, you could map them to your custom domain using
/users as your base path for the first and
/products as the base path for the second.
We’ve got a couple resources on setting this up:
a blog post on using a custom domain name with your Serverless service; and
a blog post on putting multiple Serverless services under the same custom domain, which I believe is what you’re looking for.
Both posts use the excellent serverless-domain-manager plugin from the fine people at Amplify Education.
Looks exactly what I was hoped for. Thanks!
For future readers, serverless allows this natively. If the API gateway already exists, add a configuration block in the provider section of serverless.yaml like this:
apiGateway: restApiId: xxxxxxxxxx # The resource ID of your API Gateway (can be found in the console in your API Gateway's base URL) restApiRootResourceId: xxxxxxxxxx # Root resource ID- this is the ID of the existing root path where you want this service to be mounted (might be for the API Gateway's base root "/" or for some other base path you want to use in front of your functions' paths like "/subpath".)
Other configuration options are available, see: https://www.serverless.com/framework/docs/providers/aws/guide/serverless.yml/