在 Media CDN 路徑中部署 Service Extensions 外掛程式

本頁面說明如何在 Media CDN 路徑中部署 Service Extensions 外掛程式。

您可以使用 Media CDN 搭配 Service Extensions,在要求-回應處理路徑中加入自訂程式碼。這類自訂功能可用於各種輕量用途。

如要進一步瞭解 Service Extensions 概念,請參閱Service Extensions 總覽

事前準備

  1. 建立 Media CDN 來源
  2. 建立 Media CDN 服務
  3. 使用服務擴充功能建立外掛程式

在 Media CDN 路徑中部署 Service Extensions 外掛程式

如要在 Media CDN 路徑中部署 Service Extensions 外掛程式,請按照下列步驟操作:

  1. 如要將服務目前的設定匯出至 YAML 檔案,請執行 gcloud edge-cache services export 指令

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

    更改下列內容:

    • SERVICE_NAME:Media 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:Media CDN 服務名稱
    • DOMAIN_NAME:Media CDN 服務的網域
    • PROJECT_NUMBER專案編號
    • ORIGIN_NAME:內容來源
    • WASM_ACTION:Service Extensions WASM 動作
  4. 儲存 YAML 檔案。

  5. 執行 gcloud edge-cache services import 指令

      gcloud edge-cache services import SERVICE_NAME \
          --source=FILENAME.yaml
    

後續步驟