Attach a plugin to a Media CDN route

Preview

This product or feature is subject to the "Pre-GA Offerings Terms" in the General Service Terms section of theService Specific Terms. Pre-GA products and features are available "as is" and might have limited support. For more information, see thelaunch stage descriptions.

This page describes how to configure Service Extensions plugins inMedia CDN routes.

You can use Media CDN with Service Extensionsto add custom code to the request-response processing path. Such customizationunlocks a wide variety of lightweight use cases.

For more information, seeMedia CDN extensions overview.

Before you begin

  1. Create a Media CDN origin
  2. Create a Media CDN service
  3. Create a plugin by using Service Extensions
Note: Service Extensions plugins run after all other configurablefeatures of Media CDN have run.

Create a Wasm action for a plugin

When creating a Wasm action, you can't use a plugin that's already in use in aCloud Load Balancing extension.

Create a Wasm action for your Service Extensions plugin by running thegcloud alpha service-extensions wasm-actions create command:

gcloud alpha service-extensions wasm-actions createWASM_ACTION \    --wasm-plugin=WASM_PLUGIN \    --supported-events=[EVENT,...]

Replace the following:

  • WASM_ACTION: the ID or the fully qualified nameof the Wasm action
  • WASM_PLUGIN: the name of the plugin to which youwant to attach the action
  • EVENT: the portion of the payload to be processedby the plugin as indicated by either or both of these values:request-headers orresponse-headers. If not specified, bothheaders are processed.

It might take some time for a Wasm action to be created.

Attach a plugin to a route

To attach a plugin in a Media CDN route, follow these steps:

  1. To export the current configuration of your service to a YAML file, run thegcloud edge-cache services export command:

    gcloudedge-cacheservicesexportSERVICE_NAME\--destination=FILENAME.yaml

    Replace the following:

    • SERVICE_NAME: the name of the Media CDN service
    • FILENAME: the name of the YAML file
  2. Use a text editor to edit the YAML file.

  3. Update the routes in the file to add thewasmAction header as shown in the following example:

    name:SERVICE_NAMErouting:hostRules:-hosts:-DOMAIN_NAMEpathMatcher:routespathMatchers:-name:routesrouteRules:-priority:'1'description:Route 1matchRules:-prefixMatch:/pluginsorigin:projects/PROJECT_NUMBER/locations/global/edgeCacheOrigins/ORIGIN_NAMErouteAction:wasmAction:projects/PROJECT_NUMBER/locations/global/wasmActions/WASM_ACTION

    Replace the following:

    • SERVICE_NAME: the name of the Media CDN service
    • DOMAIN_NAME: the domain of the Media CDN service
    • PROJECT_NUMBER: theproject number
    • ORIGIN_NAME: the origin for the content
    • WASM_ACTION: the Service Extensions Wasm action
  4. Save the YAML file.

  5. Run thegcloud edge-cache services import command:

    gcloudedge-cacheservicesimportSERVICE_NAME \--source=FILENAME.yaml

It might take some time for the new plugin to be distributed across alllocations. The time might vary across locations because the plugin isn'tdelivered to all locations simultaneously.

What's next

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2025-12-17 UTC.