Skip to content
This documentation is also available as markdown. For a complete index of all pages, see llms.txt at /llms.txt

CloudFront Embedder Guide

This document describes how to apply Doverunner watermark embedder with Lambda@Edge for service sites using the Amazon CloudFront CDN.

sequenceDiagram
    box End User
    participant A as End user
    end
    box Content Service
    participant C as Cloud Front CDN
    end
    A ->> C: Start playback of Session URL (request segments)
    Note right of C: Watermark embedder 
    C -->> C: Segments mixing by Session URL
    C ->> A: Send mixed segments
    Note right of A: Playback of mixed content

This AWS CDK sample contains the source code which generates the aws resources needed to set up the CloudFront embedder.

CloudFront Embedder CDK sample

CloudFront Embedder files needed for setting up Lambda@Edge can be downloaded from the Sample download page.

This video is a tutorial about how to embed Forensic Watermarking using CloudFront Embedder.

If you are unfamiliar with using Lambda@Edge with Amazon CloudFront CDN, it is recommended to make yourself familiar with the usage by referring to the AWS online documents below before proceeding to the next step.

First, you need to create the required IAM permissions and execution role to configure Lambda@Edge. In the IAM service screen of the AWS console, create the permissions and roles as follows by refer to the AWS guide.

  • Create a role by adding the permissions lambda:GetFunction, lambda:EnableReplication*, iam:CreateServiceLinkedRole, cloudfront:UpdateDistribution, and cloudfront:CreateDistribution.

To add permission, you must first specify the target service (Lambda). Also, to add lambda:EnableReplication* permission, first add lambda:EnableReplication permission and then modify the JSON code.

The policy editor shows a warning for iam:CreateServiceLinkedRole with "Resource": "*". Optionally, scope the resource to arn:aws:iam::*:role/aws-service-role/replicator.lambda.amazonaws.com/*.

  • Add log-related permission to collect Lambda access log into cloudwatch logs.

    {
    "Effect": "Allow",
    "Action": [
    "logs:CreateLogGroup",
    "logs:CreateLogStream",
    "logs:PutLogEvents"
    ],
    "Resource": "arn:aws:logs:*:*:*"
    }
  • Add the following roles to the Trust Relationship tab of the created Role.

    {
    "Version": "2012-10-17",
    "Statement": [
    {
    "Effect": "Allow",
    "Principal": {
    "Service": [
    "lambda.amazonaws.com",
    "edgelambda.amazonaws.com"
    ]
    },
    "Action": "sts:AssumeRole"
    }
    ]
    }
  • Go to the Lambda service in the AWS console and click the Create function button.
  • Select US East (N. Virginia) as the AWS Region in the upper right corner of the console. (Lambda@Edge must be created in the Virginia Region to use it.)
  • Function Name: Enter any name to identify the function. (e.g. fwm-cf-embedder)
  • Runtime: Select Node.js 24.x.
  • Architecture: Use x86_64. In Additional settings, leave the ARM64 architecture toggle off.
  • In Additional settings, turn on Custom execution role. In the Configure custom execution role panel, select the IAM role created in the previous step and click Save.
  • Click the Create function button at the bottom of the screen to create a Lambda@Edge function.
  • Click Update > Update from a .zip file on the Code source screen to upload the CloudFront Embedder zip file downloaded from the Sample Download Page.

  • Check the uploaded sample code and modify the following items.

Please be aware that if you modify a source other than those listed below, an error may occur.

  • In the config.js source, set the value of the corresponding variables as below.
NameRequiredDescription
aesKeyTrueEnter the site key value provided by the Doverunner console site.
typeTrueEnter unlabeled_a_variant if preprocessed A/B version segments are stored together in one folder (B version files have a b. prefix), and enter directory_prefix if they are packaged in separate 0 and 1 folders. Check the output folder in your storage before you set this value. Content preprocessed with the T&P service is stored in separate 0 and 1 folders, so use directory_prefix. If the value does not match the folder structure, S3 returns 403 AccessDenied. (default: unlabeled_a_variant)
availableIntervalTrueThe URL requested for watermarking contains a timestamp value. This item is the value for checking the validity of the timestamp. If set to 0, the timestamp validity period is not checked. The sample config.js sets 60. (Unit: minutes)
prefixFolderTrueSet the name of the parent folder where the A/B version contents are stored
- For contents packaged with old version packaging service: dldzkdpsxmdnjrtm
- For contents packaged with the new T&P service: wm-contents
The sample config.js sets ["wm-contents"].
wmtPublicKeyFalseSet when using the wmt token type. Use the Akamai public key issued from the Doverunner site. It can be requested the helpdesk.
wmtPasswordFalseSet when using the wmt token type. Use the Akamai password issued from the Doverunner site. It can be requested the helpdesk.

The syncSkipBit option added in embedder 2.10.0 is not a config.js setting. The embedder reads it from the session URL payload (sync_skip_bit) and uses -1 if it is not set, so you do not need to configure it.

  • After saving, click Publish new version of Action button to create version.

  • Copy the ARN containing the generated version. It is displayed in the upper right corner.

    • e.g. arn:aws:lambda:us-east-1:{account no.}:function:{lambda name}:{version}

You can also associate the version with a distribution from the Lambda console with Actions > Capabilities > Deploy to Lambda@Edge.

You can apply Lambda@Edge to an existing CloudFront distribution or to a new one. The distribution creation wizard has no function association step, so in both cases you associate the function after the distribution is created.

If you already have a distribution that serves the watermarked content, skip to Apply Lambda@Edge.

Select the CloudFront menu in the AWS console, click Create distribution, and complete the wizard steps below.

  1. Choose a plan: Select Pay as you go.
  2. Get started: Enter a name for the distribution.
  3. Specify origin: Select the S3 bucket where the A/B version content is stored. Keep Allow private S3 bucket access to CloudFront selected. CloudFront creates an origin access control (OAC) and adds the required statement to the bucket policy automatically.
  4. Enable security: AWS WAF security protections are enabled by default and incur additional charges. Choose whether to enable them for your service.
  5. Review: Check the settings and create the distribution.

Connect to the AWS console, select the CloudFront menu and select the distribution to apply Lambda@Edge.

  • Select the Behaviors tab, select the Default (*) behavior, and click the Edit button.

  • In Function associations, configure Viewer request.

    • Function type : select Lambda@Edge
    • Function ARN : input the ARN copied during Lambda@Edge creation process.
  • Click the Save changes button.

In the distribution list, Status stays Enabled, and Last modified shows Deploying while the change is deployed. When Last modified shows a date, Lambda@Edge is applied and all settings are completed.

For more information about Lambda@Edge, please refer to CloudFront guide from AWS.

If the player runs on a different origin from the CloudFront distribution, the distribution must return CORS headers. Attach a custom response headers policy to the behavior where Lambda@Edge is associated.

  • In Policies > Response headers, create a response headers policy and enable Cross-origin resource sharing (CORS). Set Access-Control-Allow-Origin, Access-Control-Allow-Headers, and Access-Control-Allow-Methods for your player (e.g. All origins, All headers, All methods), and select Origin override.
  • In the Edit screen of the behavior, select the policy as Response headers policy and click Save changes.
ResponseCauseAction
503 with X-Cache: LambdaExecutionError from cloudfrontThe Lambda@Edge function failed to run. A runtime the embedder sample does not support causes this error.Change the runtime to Node.js 24.x in Configuration > Runtime settings > Edit, publish a new version, and associate the new version ARN with the behavior.
403 AccessDenied returned by S3 (Server: AmazonS3)The segment path rewritten by the embedder does not exist in the bucket. The usual cause is a type value in config.js that does not match the folder structure. S3 returns 403 instead of 404 because CloudFront does not have s3:ListBucket permission.Check the folder structure, set type again, publish a new version, and associate the new version ARN with the behavior.