Custom domains for lambda functions

We are going to set-up a custom URL for our AWS lambda functions.

 

Prerequisites

Familiarity with AWS and Serverless.

 

Let's do this!

1. Make sure you have the domain in Route 53.

A few options if you don't:

2. API Gateway requests are served over HTTPS, so we need an SSL certificate.

Again, we have a few options to get this working with the Certificate Manager from AWS.

After going through the review and validation process, you will have a your certificate in "Issued" status. issued certificate  

3. Configure your Serverless function to use your new custom domain.

First, install a new serverless plugin.

npm install serverless-domain-manager --save-dev

 

Second, Add the following to your serverless.yml. Replace '<registered_domain_name>' with your domain.

plugins:
  - serverless-domain-manager

custom:
  customDomain:
    domainName: <registered_domain_name>
    basePath: ''
    stage: ${self:provider.stage}
    createRoute53Record: true

 

Third, create the custom domain.

sls create_domain
Serverless: Domain was created, may take up to 40 mins to be initialized

 

Finally, deploy the function again.

sls deploy

At the end of the Service Information block, you'll also get a Serverless Domain Manager Summary that shows the domain name associated with your domain.

 

If you need to remove the domain, simply run:

serverless delete_domain