Configuring AEM as a Cloud Service CDN to proxy a single path to an external origin

This article explains how to configure the Adobe-managed Fastly CDN in AEM as a Cloud Service to proxy requests for a specific path to an external third-party host by defining the external origin in the CDN configuration.

Description description

Environment

Adobe Experience Manager (AEM) as a Cloud Service (all versions)

Symptoms

Organizations need to proxy requests for a specific path (such as /cdn-proxy/rdstation/loader.js) on their domain through the Adobe-managed Fastly CDN to an external third-party host. Attempts to configure this via cdn.yaml using originSelectors and requestTransformations fail if custom origins aren’t defined, resulting in errors such as:

  • must NOT have additional properties, but has ‘origins’
  • Inability to select a custom origin because the allowed origin name list is empty

Rewriting the URL property alone doesn’t change the upstream host Fastly connects to, and requests continue to be routed to the default AEM publish origin. This configuration is often required to load third-party scripts without relaxing Content Security Policy (CSP) rules to allow external domains.

Cause

By default, AEM as a Cloud Service CDN configuration doesn’t allow routing to external origins unless explicitly defined in cdn.yaml. Attempting to use unsupported schema keys or omitting the origin definition results in configuration errors or requests being routed to the default AEM origin.

Resolution resolution

Follow the steps below to resolve the issue:

  1. In your cdn.yaml, add an entry under origins for the external host you wish to proxy to. For example:
  • name: <external-origin-name>

    domain: <external-host-domain>

  1. Use requestTransformations to match the incoming path and rewrite it, as needed, for the external origin. For example:

rules:

  • name: <path-rewrite-rule>
    when:
    reqProperty: originalPath
    equals: <your-path>
    actions:
  • type: transform
    reqProperty: path
    op: replace
    match: <your-path>$
    replacement: <external-path>
  1. Use originSelectors to route only the specific path to the external origin defined above. For example:

rules:

  • name: <origin-selector-rule>
    when:
    reqProperty: originalPath
    equals: <your-path>
    action:
    type: selectOrigin
    originName: <external-origin-name>
  1. (Optional) If you don’t want the CDN to cache the proxied asset, add skipCache: true to the relevant rule.
  2. Deploy the updated cdn.yaml via the Cloud Manager configuration pipeline.
  3. Verify that requests to the specified path are now proxied to the external origin as intended.
recommendation-more-help
experience-cloud-kcs-help-kbarticles