This page describes how to configure Service Extensions plugins in Media CDN routes.
You can use Media CDN with Service Extensions to add custom code to the request-response processing path. Such customization unlocks a wide variety of lightweight use cases.
For more information, see Media CDN extensions overview.
Before you begin
Create a Wasm action for a plugin
When creating a Wasm action, you can't use a plugin that's already in use in a Cloud Load Balancing extension.
Create a Wasm action for your Service Extensions plugin by running the
gcloud alpha service-extensions wasm-actions create
command:
gcloud alpha service-extensions wasm-actions create WASM_ACTION \ --wasm-plugin=WASM_PLUGIN \ --supported-events=[EVENT,...]
Replace the following:
WASM_ACTION
: the ID or the fully qualified name of the Wasm actionWASM_PLUGIN
: the name of the plugin to which you want to attach the actionEVENT
: the portion of the payload to be processed by the plugin as indicated by either or both of these values:request-headers
orresponse-headers
. If not specified, both headers 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:
To export the current configuration of your service to a YAML file, run the
gcloud edge-cache services export
command:gcloud edge-cache services export SERVICE_NAME \ --destination=FILENAME.yaml
Replace the following:
SERVICE_NAME
: the name of the Media CDN serviceFILENAME
: the name of the YAML file
Use a text editor to edit the YAML file.
Update the routes in the file to add the
wasmAction
header as shown in the following example:name: SERVICE_NAME routing: hostRules: - hosts: - DOMAIN_NAME pathMatcher: routes pathMatchers: - name: routes routeRules: - priority: '1' description: Route 1 matchRules: - prefixMatch: /plugins origin: projects/PROJECT_NUMBER/locations/global/edgeCacheOrigins/ORIGIN_NAME routeAction: wasmAction: projects/PROJECT_NUMBER/locations/global/wasmActions/WASM_ACTION
Replace the following:
SERVICE_NAME
: the name of the Media CDN serviceDOMAIN_NAME
: the domain of the Media CDN servicePROJECT_NUMBER
: the project numberORIGIN_NAME
: the origin for the contentWASM_ACTION
: the Service Extensions Wasm action
Save the YAML file.
Run the
gcloud edge-cache services import
command:gcloud edge-cache services import SERVICE_NAME \ --source=FILENAME.yaml
It might take some time for the new plugin to be distributed across all locations. The time might vary across locations because the plugin isn't delivered to all locations simultaneously.