How to upgrade CloudFront Node.js from v1 to v3

From Node.js runtime version 24 onward, callback-based function handlers have been removed and replaced by the async/await pattern.
According to the supported runtimes list of AWS, the Node.js runtimes prior to this version will all be deprecated in April 2027.

This guide will help you navigate through changes included in version 3 of the DataDome CloudFront Node.js module for a successful upgrade.

Overview of the changes

  • Migrate callback-based function to async/await pattern
  • Migrate from CommonJS to ES Module

Choose your migration path

Depending on your use case, follow one of the migration process.

How to migrate a single file in the Lambda@Edge function?

If you only have a datadome.js file in your Lambda function, you just have to follow the upgrade section of the documentation to use the latest version of the module.

How to migrate multiple files in the Lambda@Edge function?

If you have multiple files in your Lambda function aside the DataDome's module, you need to:

  • follow the documentation about how to use an existing Lambda@Edge function to retrieve the latest version of the module and use it inside your code
  • migrate your code from callback-based function signature for the async/await pattern function signature:
    • The responses should be returned
    • The errors should be thrown
exports.handler = (event, context, callback) => {
  // Your code here
  try {
    callback(null, {
      statusCode: 200,
      body: JSON.stringify({
        message: "Operation completed successfully"
      })
    });
  } catch (error) {
    callback(error);
  }
}
exports.handler = async (event, context) => {
  // Your code here
  try {
    return {
      statusCode: 200,
      body: JSON.stringify({
        message: "Operation completed successfully"
      })
    };
  } catch (error) {
    throw error;
  }
}
  • change the module format from CommonJS to ES Module as shown in this AWS documentation.
    It includes:
    • renaming your .js files to .mjs files to specify that you are using ES Module
    • changing your module.exports occurrences to export keyword
    • changing your const module = require('module-name') occurrences to import module from 'module-name'

How to migrate when using CloudFormation?

If you are managing your Lambda function with CloudFormation, you just have to follow the upgrade section of the documentation to use the latest version of the module.

What to do after migrating to the async/await pattern?

Update your Node.js runtime version

📘

If you are using CloudFormation to manage your Lambda function, it will already use the latest runtime version.

Since your code is now using async/await pattern, you can now upgrade your Node.js runtime's version to the latest one:

  • On your Lambda function, click on the "Edit" button on the "Runtime settings" part
  • Choose the latest Node.js runtime and save
  • Click on the "Actions" button and "Deploy to Lambda@Edge"

Split exclusion settings

Move any static-asset extensions out of DATADOME_URI_REGEX_EXCLUSION :

  • DATADOME_URI_REGEX_EXCLUSION now holds only your own URL exclusions.
  • DATADOME_STATIC_ASSET_EXCLUSION (new) holds static-asset extensions: standard list, on by default.
- DATADOME_URI_REGEX_EXCLUSION="/health|/heartbeat|\.(avi|avif|bmp|css|eot|flac|flv|gif|gz|ico|jpeg|jpg|js|json|less|map|mka|mkv|mov|mp3|mp4|mpeg|mpg|ogg|ogm|opus|otf|png|svg|svgz|swf|ttf|wav|webm|webp|woff|woff2|xml|zip)$"
+ DATA

Review additional URI checks (enabled by default)

Review each setting and disable it only if necessary for compatibility with your application.

  • Matrix params DATADOME_REMOVE_MATRIX_PARAMS): like query params (?), DataDome ignores matrix params (;) before regex evaluation.
  • Encoding DATADOME_ENCODED_CHAR_INCLUSION): DataDome inspects static-looking paths containing one of %23 %25 %2f %3b %3f.

For more information, see Split exclusion settings and default checks.


Did this page help you?