在媒体 CDN 路由中部署 Service Extensions 插件

本页面介绍了如何在 Google Cloud 上部署 Service Extensions 插件, 媒体 CDN 路由。

您可以将媒体 CDN 与服务扩展程序搭配使用 将自定义代码添加到请求-响应处理路径。这种自定义 解锁各种轻量级用例。

如需详细了解服务扩展概念,请参阅 Service Extensions 概览

准备工作

  1. 创建媒体 CDN 来源
  2. 创建媒体 CDN 服务
  3. 使用 Service Extensions 创建插件

在媒体 CDN 路由中部署 Service Extensions 插件

在媒体 CDN 中部署 Service Extensions 插件 请按以下步骤操作:

  1. 如需将服务的当前配置导出到 YAML 文件,请运行以下命令: gcloud edge-cache services export 命令

      gcloud edge-cache services export SERVICE_NAME \
          --destination=FILENAME.yaml
    

    替换以下内容:

    • SERVICE_NAME: 媒体 CDN 服务
    • FILENAME:YAML 文件的名称
  2. 在 Cloud Shell 中,使用文本编辑器来修改 YAML 文件。

  3. 更新该文件中的路由以添加 wasmAction 标头,如 请参阅以下示例:

      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
    

    替换以下内容:

    • SERVICE_NAME: 媒体 CDN 服务
    • DOMAIN_NAME: 媒体 CDN 服务
    • PROJECT_NUMBER项目编号
    • ORIGIN_NAME:内容的来源
    • WASM_ACTION:服务扩展 WASM 操作
  4. 保存 YAML 文件。

  5. 运行 gcloud edge-cache services import 命令

      gcloud edge-cache services import SERVICE_NAME \
          --source="FILENAME"
    

后续步骤