How to migrate from Lambda@Edge to CloudFront Function
This guide helps you move your CloudFront distribution from the DataDome Lambda@Edge Node.js module to the DataDome CloudFront Function module. The new module has several advantages:
- 60% lower cost than the Lambda@Edge
- Sharper detection of bad bots and malicious AI agents, including TLS fingerprinting (JA3 and JA4)
- Enriched logs for faster incident response and SIEM correlation
- Scales to millions of requests per second
DocumentationFor the full setup steps and settings of the new module, see the CloudFront Function documentation.
Overview of the changes
- Two CloudFront functions replace the Lambda@Edge function: a viewer request function that calls the DataDome API, and a viewer response function that adds DataDome's cookies and headers to the responses of allowed requests. The Lambda@Edge module returns them on challenge responses only.
- The viewer request function calls the DataDome API through an origin of your distribution,
api-functions.datadome.co. You add this origin to your distribution. - The module ships as two minified files in the module package. You do not upload a zip file or create an IAM role.
- Some Lambda@Edge features are unavailable. Read Limitations and incompatibilities before you migrate.
Limitations and incompatibilities
CloudFront does not accept a Lambda@Edge function and a CloudFront function on the same event type of the same behavior.
Each behavior uses one module or the other. For example, you can keep Lambda@Edge on the GraphQL or MCP behaviors and move the other behaviors to the CloudFront Function module.
| Lambda@Edge | CloudFront Function |
|---|---|
| GraphQL support: operation type and name read from the request body | Not supported. CloudFront Functions cannot read the request body. GraphQL requests are still protected. |
| MCP support: MCP information read from the request body | Not supported. CloudFront Functions cannot read the request body. MCP requests are still protected. |
URI inclusion (DATADOME_URI_REGEX) | Not supported as a setting. To protect only some paths, write a negative lookahead in DATADOME_URI_REGEX_EXCLUSION, for example /^(?!\/login\/)/i to protect only /login/. |
X-Forwarded-Host instead of Host (DATADOME_USE_X_FORWARDED_HOST) | Not supported. |
Custom fields, user ID and product ID (DATADOME_CUSTOM_FIELD_*, DATADOME_USER_ID, DATADOME_PRODUCT_ID) | Not supported. |
Settings mapping
Copy your values into the configuration block at the top of datadome-cf-function-viewer-request.js.
| Lambda@Edge (environment variable / CloudFormation parameter) | CloudFront Function | Notes |
|---|---|---|
DATADOME_LICENSE_KEY / DataDomeServerSideKey | DATADOME_SERVER_SIDE_KEY | Required. The same server-side key. |
DATADOME_URI_REGEX_EXCLUSION (DataDomeUriRegexExclusion) | DATADOME_URI_REGEX_EXCLUSION | Same name, same behavior. Write it as a regular expression literal, for example /^\/health/i. |
DATADOME_STATIC_ASSET_EXCLUSION (DataDomeStaticAssetExclusion) | DATADOME_STATIC_ASSET_EXCLUSION | Same name, behavior and default. |
DATADOME_ENCODED_CHAR_INCLUSION (DataDomeEncodedCharInclusion) | DATADOME_ENCODED_CHAR_INCLUSION | Same name, behavior and default. |
DATADOME_REMOVE_MATRIX_PARAMS (DataDomeRemoveMatrixParams) | DATADOME_REMOVE_MATRIX_PARAMS | Same name, behavior and default (true). |
DATADOME_LOG_BOT_INFO (DataDomeLogBotInfo) | — | Always on: the enriched headers go to the CloudFront access logs (viewer-request-log-data field) instead of CloudWatch. |
API endpoint (api-lambda.datadome.co) | DATADOME_ENDPOINT_ORIGIN_ID | Name of the distribution origin pointing to api-functions.datadome.co. Default: api-functions.datadome.co. |
| — | DATADOME_REFERRER_RESTORATION | New. Restores the original Referer after a challenge. false by default. |
Timeout, maximum sockets (DATADOME_MAX_SOCKETS), URI inclusion, X-Forwarded-Host, GraphQL, MCP, custom fields, user ID, product ID | — | Not supported (see Limitations and incompatibilities). |
Migrate your distribution
1. Install the CloudFront Function module
Follow the CloudFront Function documentation, steps 1 to 4:
- Add the DataDome API origin
api-functions.datadome.coto your distribution. - Create the viewer request function. In its configuration block, set your values (see Settings mapping).
- Create the viewer response function.
- Create the origin request policy that forwards the TLS fingerprints (
CloudFront-Viewer-JA3-FingerprintandCloudFront-Viewer-JA4-Fingerprint).
These steps leave the traffic unchanged, because no behavior uses the functions yet.
2. Switch each behavior
For each behavior protected by the Lambda@Edge module:
- Open Behaviors > select the behavior > Edit.
- Under Cache key and origin requests, set the Origin request policy to the policy from step 1.
- Under Function associations:
- Viewer request: change the function type from Lambda@Edge to CloudFront Functions. Then select the viewer request function.
- Viewer response: set the function type to CloudFront Functions. Then select the viewer response function.
- Save the changes.
- Wait until the distribution deployment is complete.
Test on one behavior first
- Switch one behavior.
- Make sure that the protection works in your DataDome dashboard.
- Switch the other behaviors.
3. Remove the Lambda@Edge module
Keep the Lambda function until all behaviors use the CloudFront Function module and the protection works. You need the function to roll back (see How to roll back to Lambda@Edge).
When no behavior uses the Lambda@Edge function anymore:
- Wait until CloudFront deletes the Lambda@Edge replicas. This takes a few hours after you remove the last association. Before that, you cannot delete the Lambda function.
- Remove the module:
- If you installed the Lambda@Edge module with CloudFormation: delete the DataDome stack. CloudFormation then removes the Lambda@Edge association, the response headers policy, and the 403 custom error response that the stack added. The CloudFront Function module does not need this 403 custom error response. Note that the deletion of the Lambda@Edge can fail when it is still associated on CloudFront distribution and may need a retry after a few hours.
- If you installed the Lambda@Edge module manually: delete the Lambda function and its IAM role. If you added a 403 custom error response for DataDome, remove it.
How to roll back to Lambda@Edge
To roll back a behavior, set its Viewer request association back to the Lambda@Edge function version. Then remove the Viewer response CloudFront function.
Updated about 7 hours ago

