[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["很难理解","hardToUnderstand","thumb-down"],["信息或示例代码不正确","incorrectInformationOrSampleCode","thumb-down"],["没有我需要的信息/示例","missingTheInformationSamplesINeed","thumb-down"],["翻译问题","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2024-12-22。"],[[["\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."]]