Skip to content

Add lambda-microvm-custom-domain-cdk pattern - #3292

Open
tanfrank wants to merge 1 commit into
aws-samples:mainfrom
tanfrank:lambda-microvm-custom-domain-cdk
Open

Add lambda-microvm-custom-domain-cdk pattern#3292
tanfrank wants to merge 1 commit into
aws-samples:mainfrom
tanfrank:lambda-microvm-custom-domain-cdk

Conversation

@tanfrank

@tanfrank tanfrank commented Aug 27, 2026

Copy link
Copy Markdown

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.

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).
```

----
Copyright 2025 Amazon.com, Inc. or its affiliates. All Rights Reserved.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Node 18 has reached EOL


this.applyHostRewrite(forwardingRule, cfg.customDomainBase, cfg.microvmEndpointBase);

// --- Route53: wildcard alias to the ALB -------------------------------

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

description must be 175 characters or fewer

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants