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
Set up CloudFront Embedder using AWS CDK
Section titled “Set up CloudFront Embedder using AWS CDK”This AWS CDK sample contains the source code which generates the aws resources needed to set up the CloudFront embedder.
CloudFront Embedder CDK sample
Set up CloudFront Embedder yourself
Section titled “Set up CloudFront Embedder yourself”CloudFront Embedder files needed for setting up Lambda@Edge can be downloaded from the Sample download page.
Tutorial Video
Section titled “Tutorial Video”This video is a tutorial about how to embed Forensic Watermarking using CloudFront Embedder.
Lambda@Edge User Guide
Section titled “Lambda@Edge User Guide”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.
- Get started creating and using Lambda@Edge functions
- Tutorial: Creating a simple Lambda@Edge function
Create IAM Permissions and Roles
Section titled “Create IAM Permissions and Roles”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, andcloudfront:CreateDistribution.
To add permission, you must first specify the target service (Lambda). Also, to add
lambda:EnableReplication*permission, first addlambda:EnableReplicationpermission and then modify the JSON code.
The policy editor shows a warning for
iam:CreateServiceLinkedRolewith"Resource": "*". Optionally, scope the resource toarn: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 Relationshiptab of the created Role.{"Version": "2012-10-17","Statement": [{"Effect": "Allow","Principal": {"Service": ["lambda.amazonaws.com","edgelambda.amazonaws.com"]},"Action": "sts:AssumeRole"}]}
Create Lambda@Edge function
Section titled “Create Lambda@Edge function”- Go to the
Lambdaservice in the AWS console and click theCreate functionbutton. - 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.)
1. Function name and Runtime settings
Section titled “1. Function name and Runtime settings”Function Name: Enter any name to identify the function. (e.g. fwm-cf-embedder)Runtime: SelectNode.js 24.x.Architecture: Usex86_64. InAdditional settings, leave theARM64 architecturetoggle off.
2. Set the execution role
Section titled “2. Set the execution role”- In
Additional settings, turn onCustom execution role. In theConfigure custom execution rolepanel, select the IAM role created in the previous step and clickSave. - Click the
Create functionbutton at the bottom of the screen to create a Lambda@Edge function.
3. Upload and edit sample code
Section titled “3. Upload and edit sample code”-
Click
Update > Update from a .zip fileon theCode sourcescreen 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.jssource, set the value of the corresponding variables as below.
| Name | Required | Description |
|---|---|---|
aesKey | True | Enter the site key value provided by the Doverunner console site. |
type | True | Enter 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) |
availableInterval | True | The 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) |
prefixFolder | True | Set 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-contentsThe sample config.js sets ["wm-contents"]. |
wmtPublicKey | False | Set when using the wmt token type. Use the Akamai public key issued from the Doverunner site. It can be requested the helpdesk. |
wmtPassword | False | Set when using the wmt token type. Use the Akamai password issued from the Doverunner site. It can be requested the helpdesk. |
The
syncSkipBitoption added in embedder 2.10.0 is not aconfig.jssetting. The embedder reads it from the session URL payload (sync_skip_bit) and uses-1if it is not set, so you do not need to configure it.
-
After saving, click
Publish new versionofActionbutton 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}
- e.g.
You can also associate the version with a distribution from the Lambda console with
Actions>Capabilities>Deploy to Lambda@Edge.
Configure CloudFront
Section titled “Configure CloudFront”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.
Create a distribution
Section titled “Create a distribution”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.
Choose a plan: SelectPay as you go.Get started: Enter a name for the distribution.Specify origin: Select the S3 bucket where the A/B version content is stored. KeepAllow private S3 bucket access to CloudFrontselected. CloudFront creates an origin access control (OAC) and adds the required statement to the bucket policy automatically.Enable security: AWS WAF security protections are enabled by default and incur additional charges. Choose whether to enable them for your service.Review: Check the settings and create the distribution.
Apply Lambda@Edge
Section titled “Apply Lambda@Edge”Connect to the AWS console, select the CloudFront menu and select the distribution to apply Lambda@Edge.
1. Set Behaviors
Section titled “1. Set Behaviors”-
Select the
Behaviorstab, select theDefault (*)behavior, and click theEditbutton. -
In
Function associations, configureViewer request.- Function type : select
Lambda@Edge - Function ARN : input the ARN copied during Lambda@Edge creation process.
- Function type : select
-
Click the
Save changesbutton.
2. Finish configuration
Section titled “2. Finish configuration”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.
Configure CORS
Section titled “Configure CORS”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 enableCross-origin resource sharing (CORS). SetAccess-Control-Allow-Origin,Access-Control-Allow-Headers, andAccess-Control-Allow-Methodsfor your player (e.g.All origins,All headers,All methods), and selectOrigin override. - In the
Editscreen of the behavior, select the policy asResponse headers policyand clickSave changes.
Troubleshooting
Section titled “Troubleshooting”| Response | Cause | Action |
|---|---|---|
503 with X-Cache: LambdaExecutionError from cloudfront | The 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. |