/license.xml via your domain, and enforcing the Crawler Authentication Protocol (CAP) using Lambda@Edge and CloudFront Functions.
RSL License Deployment
Your RSL license needs to be accessible athttps://yourdomain.com/license.xml. CloudFront proxies this path to the Supertab Connect origin using a CloudFront Function for URI rewriting, a new origin, and a dedicated cache behavior.
CloudFront Function
Create a function with runtimecloudfront-js-2.0. This runs on viewer request and rewrites the URI before CloudFront selects the origin.
Origin
Add an origin to your distribution:Cache Behavior
Create a cache behavior for/license.xml:
| Setting | Value |
|---|---|
| Path pattern | /license.xml |
| Origin | supertab-connect-origin |
| Viewer protocol policy | Redirect HTTP to HTTPS |
| Cache policy | CachingOptimized |
| Origin request policy | AllViewerExceptHostHeader |
| Viewer request function | Your published CloudFront Function |
Use
AllViewerExceptHostHeader, not AllViewer. The SDK needs viewer headers like User-Agent for bot detection, but forwarding the Host header causes origin routing failures./license.xml behavior must sit above the default * behavior in the behaviors list. Deployment takes 10–15 minutes after saving.
Terraform Alternative
Terraform Alternative
If you manage your distribution with Terraform, use this configuration instead of the manual steps above.
CAP Enforcement
CloudFront CAP deployment combines two edge features:- CloudFront Function (viewer request): Identifies
Authorization: Licenseheaders on every request, including cache hits, without adding latency for regular traffic. - Lambda@Edge (origin request): Runs the Supertab Connect SDK to verify the token and record usage. Fires only on cache misses.
CloudFront Functions fire on every request including cache hits. Lambda@Edge origin-request fires only on cache misses. This distinction matters for billing and completeness of usage recording.
Prerequisites
You need Node.js 20+, npm, and the AWS CLI configured (aws configure or aws login).
If you have PowerUserAccess, that covers all IAM requirements. Otherwise, the deploying user needs a scoped policy.
Required IAM policy (replace YOUR_DISTRIBUTION_ID)
Required IAM policy (replace YOUR_DISTRIBUTION_ID)
Step 1: Build the Lambda Package
index.ts:
package.json:
dist/function.zip.
Step 2: Deploy to AWS
IAM execution role — Create a role that both Lambda and CloudFront’s edge service can assume. AttachAWSLambdaBasicExecutionRole for CloudWatch logging.
Trust policy:
us-east-1 (required for Lambda@Edge — CloudFront replicates it globally from there). Upload dist/function.zip with nodejs20.x runtime and the execution role from above.
Publish a version — Lambda@Edge requires a published, numbered version ARN. Do not attach $LATEST. After publishing, grant CloudFront permission to invoke the function at edge locations (lambda:GetFunction and lambda:InvokeFunction for the edgelambda.amazonaws.com principal).
Save the published version ARN — you need it in Step 4.
If you update your handler code later, upload the new zip, publish a new version, and update the behavior to point to the new version ARN.
Step 3: Create the Filtering Function
Create a CloudFront Function (cloudfront-js-2.0 runtime) that runs on viewer request. It checks whether the Authorization header contains a license token. If it does, it adds x-license-auth to the request headers — this header is used in the cache key to separate licensed and unlicensed cache entries, and its presence triggers the Lambda@Edge function on cache misses.
Step 4: Configure the Cache Behavior
Edit the behavior for the path you want to protect (the default* behavior for all requests, or a specific path like /articles/*).
Cache policy — Create a custom cache policy with x-license-auth included in the cache key headers. This ensures that requests with and without a license token produce separate cache entries — without it, a cached response from a licensed request could be served to unlicensed requests. Keep defaults for TTL, query strings, cookies, and compression.
Origin request policy — Set to AllViewerExceptHostHeader. This forwards viewer headers (including User-Agent for bot detection) to the origin while letting CloudFront set the correct origin hostname.
Do not use
AllViewer — it forwards the original Host header, which causes routing failures on S3 and API Gateway origins.| Event | Type | Value |
|---|---|---|
| Viewer request | CloudFront Functions | Your published filtering function from Step 3 |
| Origin request | Lambda@Edge | Published version ARN from Step 2 |
Related Docs
Deploy in Your CDN
CDN-agnostic guide covering RSL serving, CAP enforcement, and robots.txt.
Other CDNs
Generic CDN patterns for platforms not listed above.