logo
Published on

Custom Domain for Lambda

Authors
  • avatar
    Name
    Bowen Y
    Twitter

How to deploy a custom domain for the auto-generated Lambda invoke URL?

06 APR 2022 — AWS announced an exciting news of Built-in HTTPS Endpoints for Lambda functions. You can read the original post .

Before this announcement, to expose an HTTP endpoint with a custom domain for your lambda backend you have to use the following AWS resources:

Alt text

  • Lambda (application backend)
  • API Gateway (to expose HTTP endpoint)
  • Cloudfront distribution
  • Route 53

Fortunately, with AWS Lambda URLs you no longer need the API Gateway !

This is how it looks the new architecture :

Alt text

So in this way you are able to deploy a serverless application with a custom domain using only Lambda + Cloudfront + Route 53, thanks to Lambda Function URLs.

Reference: https://medium.com/@walid.karray/configuring-a-custom-domain-for-aws-lambda-function-url-with-serverless-framework-c0d78abdc253

Can I just simply create a CNAME Route53 record and redirect the incoming requests to my custom domain to the auto-generated Lambda invoke URL?

No.

If you must use an AWS Lambda function URL, fronting it with a CloudFront distribution with your desired custom domain name is the only way currently.

There is no support currently for a Route 53 alias record, as the Host header must be set to the Lambda function URL domain. If the Host header does not exist, HTTP 400 Bad Request is returned & if it does exist but is not the correct value, HTTP 403 Forbidden is returned.

They are meant to be the simplest & fastest way to invoke your Lambda functions via a public endpoint without using other AWS services like API gateway, so a native lack of support for a custom domain name makes sense.

Reference: https://stackoverflow.com/questions/71815143/how-can-i-call-my-aws-lambda-function-url-via-a-custom-domain