每個事件來源、事件目標和 Eventarc 觸發條件都有各自的位置。有時這些位置必須相符,有時則可以不同。詳情請參閱「Eventarc 區域」。
來源位置
事件來源的位置通常會決定觸發條件位置。在下列範例中,由於 Cloud Storage bucket 位於 europe-west1
區域,觸發條件也必須位於 europe-west1
。
gcloud eventarc triggers create trigger-storage \
--destination-run-service=hello \
--destination-run-region=us-central1 \
--location=europe-west1 \
--event-filters="type=google.cloud.storage.object.v1.finalized" \
--event-filters="bucket=my-bucket-in-europe-west1-region" \
--service-account=$PROJECT_NUMBER-compute@developer.gserviceaccount.com
目標位置
部署事件目標 (例如 Cloud Run 服務) 時,請選擇支援的地區做為目標位置。通常基於延遲和資料區域性考量,您會希望這與事件來源位於相同區域。不過,這並非必要條件。在上述範例中,事件來源位於 europe-west1
,而 --destination-run-region
旗標則指出事件目標位於 us-central1
。
觸發地點
此外,您建立的 Eventarc 觸發條件類型會影響觸發條件的位置,該位置是透過 --location
旗標指定:
Cloud 稽核記錄
使用 Cloud Audit Logs 觸發條件,您可以將發出稽核記錄的任何事件來源,連結至事件目標。Cloud Audit Logs 觸發程序適用於單一區域位置,您也可以建立全域 Eventarc 觸發程序;不過,雙區域和多區域位置不支援觸發程序。
事件來源的位置會決定觸發條件位置。通常這是單一區域位置。舉例來說,如要使用稽核記錄觸發條件,從 europe-west1
區域的 bucket 擷取 Cloud Storage 事件,請在相同位置建立觸發條件:
gcloud eventarc triggers create trigger-auditlog \
--destination-run-service=hello \
--destination-run-region=us-central1 \
--location=europe-west1 \
--event-filters="type=google.cloud.audit.log.v1.written" \
--event-filters="serviceName=storage.googleapis.com" \
--event-filters="methodName=storage.objects.create" \
--service-account=$PROJECT_NUMBER-compute@developer.gserviceaccount.com
使用 Cloud 稽核記錄觸發程序時,系統不會依值區進行篩選,因此這會比對 europe-west1
地區中的所有值區。(如要依 bucket 篩選,請改用直接 Cloud Storage 觸發程序)。
或者,如要比對雙區域或多區域值區 (例如 eu
),您可以建立具有 global
位置的觸發條件,這樣一來,只要事件篩選條件相符,系統就會比對所有區域中的所有值區:
gcloud eventarc triggers create trigger-storage \
--destination-run-service=hello \
--destination-run-region=us-central1 \
--location=global \
--event-filters="type=google.cloud.storage.object.v1.finalized" \
--event-filters="bucket=my-bucket-in-europe-west1-region" \
--service-account=$PROJECT_NUMBER-compute@developer.gserviceaccount.com
Cloud Storage
Cloud Storage 觸發程序會回應 Cloud Storage 值區內的事件,包括物件建立、刪除、封存和中繼資料更新。Cloud Storage 觸發程序適用於單一區域、雙區域和多區域位置,您無法建立全域 Eventarc 觸發程序。
Cloud Storage 值區的位置會決定 Eventarc 觸發條件的位置,兩者必須一致。在下列範例中,觸發位置與 Cloud Storage 值區的位置 (eu
多區域位置) 相符:
gcloud eventarc triggers create trigger-storage \
--destination-run-service=hello \
--destination-run-region=us-central1 \
--location=eu \
--event-filters="type=google.cloud.storage.object.v1.finalized" \
--event-filters="bucket=my-bucket-in-eu-multi-region" \
--service-account=$PROJECT_NUMBER-compute@developer.gserviceaccount.com
如果 bucket 和觸發程序區域不相符,您會看到類似下列內容的錯誤:
ERROR: (gcloud.eventarc.triggers.create) INVALID_ARGUMENT: The request was
invalid: Bucket "my-bucket-in-eu-multi-region" location "eu" does not match
trigger location "europe-west1". Try again by creating the trigger in "eu".
Pub/Sub
Pub/Sub 觸發條件會將 Pub/Sub 主題連結至事件目標。Pub/Sub 觸發條件僅適用於單一區域位置,您無法建立全域 Eventarc 觸發條件。
雖然 Pub/Sub 主題是全球資源,不與單一區域綁定,但建立 Pub/Sub 觸發條件時,您必須使用 --location
標記為其指定區域:
gcloud eventarc triggers create trigger-pubsub \
--destination-run-service=hello \
--destination-run-region=us-central1 \
--location=us-central1 \
--event-filters="type=google.cloud.pubsub.topic.v1.messagePublished" \
--transport-topic=projects/your-projectid/topics/your-topic
Eventarc 會設定地理圍欄,確保 Pub/Sub 事件只保留在指定位置。您也可以使用區域性 Pub/Sub 服務端點發布至主題,確保所有資料都留在單一區域。
後續步驟
- 如要瞭解如何在專案間傳送事件,請參閱 Google Cloud 教學課程。