CDN config deployment fails with ‘Could not parse yaml file’ due to regex escaping in cdn.yaml

This article explains how to resolve YAML parse errors during CDN configuration deployment in Adobe Experience Manager caused by incorrect escaping of regex strings in cdn.yaml.

Description description

Environment

Adobe Experience Manager (AEM) as a Cloud Service

Issue/Symptoms

When deploying updates to the CDN configuration (cdn.yaml) in the RDE environment, the deployment fails with the following error message:

Could not parse yaml file in 'rde/cdn.yaml'. Please check that you are using valid YAML syntax and check the documentation
  • The error appears after adding new rules or modifying regex patterns in the YAML file.
  • Deploying the unmodified, known-good cdn.yaml succeeds.
  • Changing only rule names (without modifying regex or logic) also succeeds.
  • Adding a new rule for a new locale or modifying a regex pattern with a pipe (|) operator causes the deployment to fail.
  • Isolation tests confirm that the YAML syntax is valid.

Example of problematic YAML content:

replacement: "\1/\2"
 matches: "/en_us/(article-index|author-index|query-index)\.json$"

Example of failing YAML content (incorrect escaping):

replacement: "\1/\2"
 matches: "/en_us/(article-index|author-index|query-index)\.json$"

Cause

The deployment pipeline misreports YAML parse errors when regex strings and backreferences are not properly escaped in the YAML file. Using single quotes for regex strings or ensuring correct escaping resolves the issue.

Resolution resolution

To fix the CDN config deployment failure issue, follow these steps:

  1. Review the cdn.yaml file for regex patterns and backreferences, especially in the matches and replacement fields.
  2. Escape all regex strings and backreferences correctly by using double backslashes in double-quoted strings (for example, "\\.html$"); backslashes do not require escaping in single-quoted strings (for example, '\.html$').
  3. Replace double-quoted regex strings with single-quoted strings when possible to prevent YAML escaping issues. For example, replace: match: "/en_us/blog.*" to match: '/en_us/blog.*'
  4. Update all affected fields in the YAML file. For example:
replacement: '\1/\2'
matches: '/en_us/(article-index|author-index|query-index).json$'
  1. Save and redeploy the updated cdn.yaml file.
  2. Confirm that the deployment completes successfully without parse errors.
recommendation-more-help
experience-cloud-kcs-help-kbarticles