Mit Sammlungen den Überblick behalten
Sie können Inhalte basierend auf Ihren Einstellungen speichern und kategorisieren.
Cloud Storage-Trigger (1. Generation)
In Cloud Run Functions ermöglicht ein Cloud Storage-Trigger das Aufrufen einer Funktion als Reaktion auf Änderungen in Cloud Storage. Wählen Sie einen Ereignistyp aus und geben einen Cloud Storage-Bucket an, wenn Sie einen Cloud Storage-Trigger für eine Funktion angeben. Die Funktion wird immer dann aufgerufen, wenn eine Änderung an einem Objekt (Datei) im angegebenen Bucket erfolgt.
Die folgenden Cloud Storage-Ereignistypen werden unterstützt:
Ereignis
Ereignistyp
Beschreibung
Objekt abgeschlossen
google.storage.object.finalize
Tritt auf, wenn ein neues Objekt erstellt oder ein vorhandenes Objekt überschrieben und eine neue Generierung dieses Objekts erstellt wird.
Objekt gelöscht
google.storage.object.delete
Tritt auf, wenn ein Objekt endgültig gelöscht wird.
Objekt archiviert
google.storage.object.archive
Tritt auf, wenn eine Liveversion eines Objekts zu einer nicht aktuellen Version wird.
Weitere Informationen finden Sie unter Objektversionsverwaltung.
Objektmetadaten aktualisiert
google.storage.object.metadataUpdate
Tritt auf, wenn sich die Metadaten eines vorhandenen Objekts ändern.
Damit eine Funktion einen Cloud Storage-Trigger verwenden kann, muss sie als ereignisgesteuerte Funktion implementiert werden:
Wenn Sie eine Hintergrundfunktion verwenden, wird die Nutzlast der Cloud Storage-Ereignisdaten direkt an die Funktion im StorageObjectData-Format weitergegeben.
Das Repository Google Events enthält zusätzliche Ressourcen für die Arbeit mit Ereignisdaten.
Bereitstellung
Sie können einen Cloud Storage-Trigger angeben, wenn Sie eine Funktion bereitstellen. Allgemeine Anleitungen zum Bereitstellen einer Funktion finden Sie unter Cloud Run Functions-Funktionen bereitstellen. Weiter unten finden Sie zusätzliche Informationen zum Konfigurieren von Cloud Storage-Triggern während der Bereitstellung.
gcloud
Wenn Sie die gcloud CLI verwenden, können Sie den Cloud Storage-Ereignistyp Objekt abgeschlossen mit den folgenden Flags verwenden:
Das Flag --trigger-bucket gibt den Cloud Storage-Bucket an, den der Trigger überwacht.
Objekt abgeschlossene Ereignisse in diesem Bucket lösen Aufrufe an Ihre Funktion aus.
Dieser Ereignistyp wird für Legacy-Funktionen unterstützt, die diese Ereignisse bereits verwenden. Wir empfehlen jedoch nicht, diesen Ereignistyp zu verwenden, da er möglicherweise in Zukunft entfernt wird.
Wählen Sie im Feld Triggertyp die Option Cloud Storage aus.
Wählen Sie im Feld Ereignistyp einen Ereignistyp aus.
Klicken Sie im Feld Bucket auf Durchsuchen, um einen Cloud Storage-Bucket auszuwählen, den der Trigger überwachen soll. Änderungen an Objekten in diesem Bucket lösen Aufrufe Ihrer Funktion aus.
Aktivieren oder deaktivieren Sie das Kästchen Bei Fehler noch einmal versuchen, um zu steuern, ob fehlgeschlagene Funktionsaufrufe automatisch wiederholt werden. Weitere Informationen finden Sie unter Ereignisgesteuerte Funktionen wiederholen.
Ein Cloud Storage-Bucket kann bis zu 10 Benachrichtigungskonfigurationen haben, die zum Auslösen von Benachrichtigungen für ein bestimmtes Ereignis festgelegt sind. Wenn Sie die Benachrichtigungslimits des Buckets überschreiten, schlagen weitere Funktionsbereitstellungen mit einem Fehler wie dem folgenden fehl:
In der Anleitung zur Cloud Storage-Funktion finden Sie ein Beispiel für das Schreiben, Bereitstellen und Aufrufen einer Funktion mit einem Cloud Storage-Trigger.
[[["Leicht verständlich","easyToUnderstand","thumb-up"],["Mein Problem wurde gelöst","solvedMyProblem","thumb-up"],["Sonstiges","otherUp","thumb-up"]],[["Schwer verständlich","hardToUnderstand","thumb-down"],["Informationen oder Beispielcode falsch","incorrectInformationOrSampleCode","thumb-down"],["Benötigte Informationen/Beispiele nicht gefunden","missingTheInformationSamplesINeed","thumb-down"],["Problem mit der Übersetzung","translationIssue","thumb-down"],["Sonstiges","otherDown","thumb-down"]],["Zuletzt aktualisiert: 2024-12-22 (UTC)."],[[["\u003cp\u003eCloud Storage triggers in Cloud Run functions (1st gen) allow functions to be activated by changes within a designated Cloud Storage bucket, specifying an event type and the bucket to monitor.\u003c/p\u003e\n"],["\u003cp\u003eSupported Cloud Storage event types include \u003ccode\u003eobject.finalize\u003c/code\u003e (new or overwritten object), \u003ccode\u003eobject.delete\u003c/code\u003e (permanent deletion), \u003ccode\u003eobject.archive\u003c/code\u003e (object becomes noncurrent), and \u003ccode\u003eobject.metadataUpdate\u003c/code\u003e (metadata changes).\u003c/p\u003e\n"],["\u003cp\u003eCloud Storage triggers use an event-driven function framework, where data is passed in CloudEvents format or \u003ccode\u003eStorageObjectData\u003c/code\u003e format, depending on the function type.\u003c/p\u003e\n"],["\u003cp\u003eDeployment of a function with a Cloud Storage trigger can be done via gcloud CLI, using \u003ccode\u003e--trigger-bucket\u003c/code\u003e, \u003ccode\u003e--trigger-event\u003c/code\u003e, and \u003ccode\u003e--trigger-resource\u003c/code\u003e flags, or via the Google Cloud console, choosing the trigger type, event type and associated bucket.\u003c/p\u003e\n"],["\u003cp\u003eA Cloud Storage bucket can only support up to 10 notification configurations, so exceeding this limit when deploying multiple functions to monitor a single bucket will lead to deployment failures.\u003c/p\u003e\n"]]],[],null,["# Cloud Storage triggers (1st gen)\n================================\n\nIn Cloud Run functions, a Cloud Storage trigger enables a function to be called\nin response to changes in [Cloud Storage](/storage/docs). When you\nspecify a Cloud Storage trigger for a function, you choose an event\ntype and specify a Cloud Storage bucket. Your function will be called\nwhenever a change occurs on an object (file) within the specified bucket.\n| **Note:** For a Cloud Run function to be triggered by an event on a Cloud Storage bucket, the function and the bucket must be in the same Google Cloud project.\n\nThe following Cloud Storage event types are supported:\n\nFor a function to use a Cloud Storage trigger, it must be implemented as an\n[event-driven function](/functions/1stgendocs/writing/write-event-driven-functions):\n\n- If you use a\n [CloudEvent function](/functions/1stgendocs/writing/write-event-driven-functions#cloudevent-functions),\n the Cloud Storage event data is passed to your function in the\n [CloudEvents format](/eventarc/docs/cloudevents) and the CloudEvent data\n payload is of type\n [`StorageObjectData`](https://github.com/googleapis/google-cloudevents/blob/main/proto/google/events/cloud/storage/v1/data.proto).\n\n- If you use a\n [background function](/functions/1stgendocs/writing/write-event-driven-functions#background-functions),\n the Cloud Storage event data payload is passed directly to your\n function in the\n [`StorageObjectData`](https://github.com/googleapis/google-cloudevents/blob/main/proto/google/events/cloud/storage/v1/data.proto)\n format.\n\nThe\n[Google Events](https://github.com/googleapis/google-cloudevents)\nrepository contains additional resources for working with event data.\n\nDeployment\n----------\n\nYou can specify a Cloud Storage trigger when you deploy a function. See\n[Deploy a Cloud Run function](/functions/1stgendocs/deploy) for\ngeneral instructions on how to deploy a function, and see the following for\nadditional information specific to configuring Cloud Storage triggers\nduring deployment. \n\n### gcloud\n\nIf you are\n[deploying using the gcloud CLI](/functions/1stgendocs/deploy#basics),\nyou can use the Cloud Storage *Object finalized* event type with the\nfollowing flags: \n\n```sh\ngcloud functions deploy YOUR_FUNCTION_NAME \\\n--no-gen2 \\\n--trigger-bucket=YOUR_STORAGE_BUCKET \\\n[--retry] \\\n...\n```\n\n- The [`--trigger-bucket`](/sdk/gcloud/reference/functions/deploy#--trigger-bucket) flag specifies the Cloud Storage bucket that the trigger will monitor. *Object finalized* events within this bucket will trigger calls to your function.\n- The [`--retry`](/sdk/gcloud/reference/functions/deploy#--retry) flag controls whether failed function calls are automatically retried. See [Retrying event-driven functions](/functions/1stgendocs/bestpractices/retries) for more information.\n\nTo use event types other than *Object finalized*, use the following flags:\n\n\u003cbr /\u003e\n\n```sh\n gcloud functions deploy YOUR_FUNCTION_NAME \n\n --no-gen2 \n\n --trigger-event=EVENT_TYPE \n\n --trigger-resource=YOUR_STORAGE_BUCKET \n\n ...\n \n```\n\n\u003cbr /\u003e\n\n**Legacy Cloud Storage events**\n\nLegacy functions in Cloud Run functions (1st gen) use legacy\n[object change notifications](/storage/docs/object-change-notification)\nfor Cloud Storage triggers: \n\n```sh\ngcloud functions deploy YOUR_FUNCTION_NAME \\\n--no-gen2 \\\n--trigger-event=providers/cloud.storage/eventTypes/object.change \\\n--trigger-resource=YOUR_STORAGE_BUCKET \\\n...\n```\n\nThis event type is supported for legacy functions already consuming these\nevents. However, we don't recommend using this event type as it might be\nremoved at a future date.\n\n### Console\n\nIf you are\n[deploying using the Google Cloud console](/functions/1stgendocs/deploy#console),\nyou can configure a Cloud Storage trigger in the **Trigger** section:\n\n1. In the **Trigger type** field, select **Cloud Storage**.\n2. In the **Event type** field, select an event type.\n3. In the **Bucket** field, click **Browse** to select a Cloud Storage bucket for the trigger to monitor. Changes to objects within this bucket will trigger calls to your function.\n4. Select or deselect the **Retry on failure** checkbox to control whether failed function calls are automatically retried. See [Retrying event-driven functions](/functions/1stgendocs/bestpractices/retries) for more information.\n\nEvent delivery\n--------------\n\nCloud Storage triggers are implemented with\n[Pub/Sub notifications for Cloud Storage](/storage/docs/pubsub-notifications).\nEvents are subject to\n[Pub/Sub notification delivery guarantees](/storage/docs/pubsub-notifications#delivery_guarantees).\n\nA Cloud Storage bucket can have up to 10 notification configurations\nset to trigger for a specific event. Exceeding the bucket's notifications limits\nwill cause further function deployments to fail with an error like the following: \n\n```\nCloud Storage bucket ...: Pub/Sub notification limit reached\n```\n\nYou can work around this limitation by\n[managing your own Pub/Sub topic](/storage/docs/reporting-changes)\nand registering it for Cloud Storage notifications of the type you want your\nfunction to respond to. For example, you could configure a single notification\nfor your chosen event (such as object creation) to a Pub/Sub topic.\nThen, have as many function subscribers as needed to the topic process the event\nand fan it out to multiple destinations. For example:\n\n1. [Create your own Pub/Sub topic](/pubsub/docs/create-topic).\n2. Create a single [notification configuration](/storage/docs/reporting-changes) on your Cloud Storage bucket that triggers on a specific event (such as `OBJECT_FINALIZE` for object creation) and sends the event to your single Pub/Sub topic.\n3. Create a function (or functions) triggered by your [Pub/Sub topic](/functions/1stgendocs/calling/pubsub).\n\nSee Cloud Storage [Quotas and limits](/storage/quotas) to learn more\nabout Cloud Storage limitations.\n\nNext steps\n----------\n\n- Learn how to [write event-driven functions](/functions/1stgendocs/writing/write-event-driven-functions).\n- Learn how to [deploy a Cloud Run function](/functions/1stgendocs/deploy).\n- See the [Cloud Storage function tutorial](/functions/1stgendocs/tutorials/storage-1st-gen) for an example of writing, deploying, and calling a function with a Cloud Storage trigger."]]