Using custom domains
Microlambda makes it very easy to use custom API Gateway domains.
The benefit is first aesthetic, allowing you to serve the API on a more elegant domain than the one generated by default by AWS. But more importantly, it enables the activation of advanced and highly interesting Route 53 features such as latency-based routing.
To enable a custom domain, you need to have a hosted zone covering the domain in your AWS account. If you don't have one, you must create it beforehand and update the NS records with your registrar.
To serve API Gateway on a custom domain, simply add the following configuration to your serverless.yml:
custom:
domain:
domainName: ${env:ENV}.api.myapp.io
The Microlambda plugin will take care of finding the nearest hosted zone for the domain. It will also find the closest certificate covering the domain, and if one doesn't exist in the subscription, it will be provisioned and activated via the DNS method. Afterward, the plugin will create both DNS records on Route53 and update the configuration on API Gateway.
If the infrastructure is replicated in multiple regions, the created records will enable latency-based routing, directing traffic to the AWS region with the lowest latency for the end user. You can learn more about this feature by reading the dedicated section.