本頁面說明如何在 Media CDN 路徑中部署 Service Extensions 外掛程式。
您可以使用 Media CDN 搭配 Service Extensions,在要求-回應處理路徑中加入自訂程式碼。這類自訂功能可用於各種輕量用途。
如要進一步瞭解 Service Extensions 概念,請參閱Service Extensions 總覽。
事前準備
在 Media CDN 路徑中部署 Service Extensions 外掛程式
如要在 Media CDN 路徑中部署 Service Extensions 外掛程式,請按照下列步驟操作:
如要將服務目前的設定匯出至 YAML 檔案,請執行
gcloud edge-cache services export
指令:gcloud edge-cache services export SERVICE_NAME \ --destination=FILENAME.yaml
更改下列內容:
SERVICE_NAME
:Media CDN 服務名稱FILENAME
:YAML 檔案名稱
在 Cloud Shell 中,使用文字編輯器編輯 YAML 檔案。
更新檔案中的路由,以便新增
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 動作
儲存 YAML 檔案。
執行
gcloud edge-cache services import
指令:gcloud edge-cache services import SERVICE_NAME \ --source=FILENAME.yaml
後續步驟
- 進一步瞭解Service Extensions 概念。
- 瞭解如何準備及上傳建立外掛程式的必要檔案,方法是使用服務擴充功能。
- 瞭解如何建立外掛程式。