Add lambda-microvm-custom-domain-cdk pattern - #3292
Open
tanfrank wants to merge 1 commit into
Open
Conversation
Custom domains for AWS Lambda MicroVMs using an Application Load Balancer Host header rewrite over PrivateLink -- no CloudFront and no compute in the request path. Includes an optional, demo-only single-page app and provisioning API that can be removed to deploy the pure networking pattern. Built with AWS CDK v2 (TypeScript).
bfreiberg
requested changes
Aug 27, 2026
| ``` | ||
|
|
||
| ---- | ||
| Copyright 2025 Amazon.com, Inc. or its affiliates. All Rights Reserved. |
Contributor
There was a problem hiding this comment.
Suggested change
| Copyright 2025 Amazon.com, Inc. or its affiliates. All Rights Reserved. | |
| Copyright 2026 Amazon.com, Inc. or its affiliates. All Rights Reserved. |
| @@ -0,0 +1,104 @@ | |||
| # Custom domains for AWS Lambda MicroVMs with Application Load Balancer | |||
Contributor
There was a problem hiding this comment.
Suggested change
| # Custom domains for AWS Lambda MicroVMs with Application Load Balancer | |
| # Custom domains for AWS Lambda MicroVMs with AWS Application Load Balancer |
|
|
||
| This pattern gives each of your [AWS Lambda MicroVMs](https://docs.aws.amazon.com/lambda/latest/dg/lambda-microvms-guide.html) a domain **you** own — e.g. `92cfc7f9-….microvms.example.com` — instead of exposing the service-generated `92cfc7f9-….lambda-microvm-….on.aws` endpoint directly. | ||
|
|
||
| It is built entirely from load-balancing and networking primitives: **no CloudFront** and **no compute in the request path** — just an Application Load Balancer (ALB) that rewrites the `Host` header with an [ALB Host header rewrite](https://aws.amazon.com/blogs/networking-and-content-delivery/introducing-url-and-host-header-rewrite-with-aws-application-load-balancers/) and forwards to the MicroVM service over AWS PrivateLink. A wildcard ACM certificate and a Route 53 wildcard record cover every MicroVM id under a single base domain. |
Contributor
There was a problem hiding this comment.
Suggested change
| It is built entirely from load-balancing and networking primitives: **no CloudFront** and **no compute in the request path** — just an Application Load Balancer (ALB) that rewrites the `Host` header with an [ALB Host header rewrite](https://aws.amazon.com/blogs/networking-and-content-delivery/introducing-url-and-host-header-rewrite-with-aws-application-load-balancers/) and forwards to the MicroVM service over AWS PrivateLink. A wildcard ACM certificate and a Route 53 wildcard record cover every MicroVM id under a single base domain. | |
| It is built entirely from load-balancing and networking primitives: **no Amazon CloudFront** and **no compute in the request path** — just an Application Load Balancer (ALB) that rewrites the `Host` header with an [ALB Host header rewrite](https://aws.amazon.com/blogs/networking-and-content-delivery/introducing-url-and-host-header-rewrite-with-aws-application-load-balancers/) and forwards to the MicroVM service over AWS PrivateLink. A wildcard [AWS Certificate Manager](https://aws.amazon.com/certificate-manager/) certificate and a Route 53 wildcard record cover every MicroVM id under a single base domain. |
|
|
||
| Important: this application uses various AWS services and there are costs associated with these services after the Free Tier usage - please see the [AWS Pricing page](https://aws.amazon.com/pricing/) for details. You are responsible for any AWS costs incurred. No warranty is implied in this example. | ||
|
|
||
| > ⚠️ **The optional demo layer is DEMO ONLY — NOT PRODUCTION-SAFE.** Its `POST /api/provision` endpoint is completely unauthenticated, it returns auth tokens to the browser, and it uses wide-open CORS (`Access-Control-Allow-Origin: *`). The **core pattern** (`MicroVmCustomDomainsStack`) is production-oriented networking, but before deploying the demo layer, put real authentication in front of the provisioning API, pin CORS to your own origin, and scope IAM and tokens to the minimum. Deploy the demo only in an isolated, non-production account. |
Contributor
There was a problem hiding this comment.
Suggested change
| > ⚠️ **The optional demo layer is DEMO ONLY — NOT PRODUCTION-SAFE.** Its `POST /api/provision` endpoint is completely unauthenticated, it returns auth tokens to the browser, and it uses wide-open CORS (`Access-Control-Allow-Origin: *`). The **core pattern** (`MicroVmCustomDomainsStack`) is production-oriented networking, but before deploying the demo layer, put real authentication in front of the provisioning API, pin CORS to your own origin, and scope IAM and tokens to the minimum. Deploy the demo only in an isolated, non-production account. | |
| > ⚠️ **The optional demo layer is DEMO ONLY — NOT PRODUCTION-SAFE.** Its `POST /api/provision` endpoint is completely unauthenticated, it returns auth tokens to the browser, and it uses wide-open CORS (`Access-Control-Allow-Origin: *`). The **core pattern** (`MicroVmCustomDomainsStack`) is production-oriented networking, but before deploying the demo layer, at least put real authentication in front of the provisioning API, pin CORS to your own origin, and scope IAM and tokens to the minimum. Deploy the demo only in an isolated, non-production account. |
| * [Create an AWS account](https://portal.aws.amazon.com/gp/aws/developer/registration/index.html) if you do not already have one and log in. The IAM user that you use must have sufficient permissions to make necessary AWS service calls and manage AWS resources. | ||
| * [AWS CLI](https://docs.aws.amazon.com/cli/latest/userguide/install-cliv2.html) installed and configured. | ||
| * [Git Installed](https://git-scm.com/book/en/v2/Getting-Started-Installing-Git). | ||
| * [Node.js 18+](https://nodejs.org/en/download/) and [AWS CDK v2](https://docs.aws.amazon.com/cdk/v2/guide/getting_started.html) installed (`npx cdk` works; no global install required). |
Contributor
There was a problem hiding this comment.
Suggested change
| * [Node.js 18+](https://nodejs.org/en/download/) and [AWS CDK v2](https://docs.aws.amazon.com/cdk/v2/guide/getting_started.html) installed (`npx cdk` works; no global install required). | |
| * [Node.js 22+](https://nodejs.org/en/download/) and [AWS CDK v2](https://docs.aws.amazon.com/cdk/v2/guide/getting_started.html) installed (`npx cdk` works; no global install required). |
|
|
||
| this.applyHostRewrite(forwardingRule, cfg.customDomainBase, cfg.microvmEndpointBase); | ||
|
|
||
| // --- Route53: wildcard alias to the ALB ------------------------------- |
Contributor
There was a problem hiding this comment.
Suggested change
| // --- Route53: wildcard alias to the ALB ------------------------------- | |
| // --- Route 53: wildcard alias to the ALB ------------------------------- |
| * | ||
| * Request flow: | ||
| * <uuid>.microvms.example.com | ||
| * -> Route53 A/AAAA alias (wildcard) -> ALB (TLS, *.customDomainBase cert) |
Contributor
There was a problem hiding this comment.
Suggested change
| * -> Route53 A/AAAA alias (wildcard) -> ALB (TLS, *.customDomainBase cert) | |
| * -> Route 53 A/AAAA alias (wildcard) -> ALB (TLS, *.customDomainBase cert) |
| "account": "111122223333", | ||
| "region": "us-east-2", | ||
|
|
||
| "//zone": "Existing Route53 public hosted zone that will hold the wildcard record.", |
Contributor
There was a problem hiding this comment.
Suggested change
| "//zone": "Existing Route53 public hosted zone that will hold the wildcard record.", | |
| "//zone": "Existing Route 53 public hosted zone that will hold the wildcard record.", |
| 'lambda:GetMicrovm', | ||
| 'lambda:CreateMicrovmAuthToken', | ||
| ], | ||
| resources: ['*'], // MicroVM ids are generated at run time; scope by account/region via the execution env. |
Contributor
There was a problem hiding this comment.
Can we scope this down to account/region here already?
| @@ -0,0 +1,65 @@ | |||
| { | |||
| "title": "Custom domains for AWS Lambda MicroVMs with Application Load Balancer", | |||
| "description": "Serve each AWS Lambda MicroVM under a domain you own using an Application Load Balancer Host header rewrite over PrivateLink, with no CloudFront and no compute in the request path.", | |||
Contributor
There was a problem hiding this comment.
description must be 175 characters or fewer
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds a new pattern: Custom domains for AWS Lambda MicroVMs with Application Load Balancer.
Each Lambda MicroVM is served under a domain you own (e.g. .microvms.example.com)
instead of the service-generated .lambda-microvm..on.aws endpoint. Built
entirely from load-balancing/networking primitives — no CloudFront and no compute in the
request path: an ALB rewrites the Host header (host-header-rewrite Transform) and forwards
to the MicroVM service over PrivateLink, with a wildcard ACM cert and Route 53 wildcard record.
Framework: AWS CDK v2 (TypeScript)
Includes: README.md, example-pattern.json, cdk.json, source, and passing tests (13/13).
The optional demo layer (single-page app + provisioning API) can be removed to deploy the
pure networking pattern.