Jika Anda membuat fungsi baru, lihat Panduan Memulai Konsol di Cloud Run. Konten di halaman ini hanya berlaku untuk fungsi lama yang sudah ada yang dibuat dengan Cloud Functions v1 API.
Tetap teratur dengan koleksi
Simpan dan kategorikan konten berdasarkan preferensi Anda.
Pemicu Cloud Storage (generasi ke-1)
Di Cloud Run Functions, pemicu Cloud Storage memungkinkan suatu fungsi dipanggil sebagai respons terhadap perubahan dalam Cloud Storage. Saat menentukan pemicu Cloud Storage untuk suatu fungsi, Anda memilih jenis peristiwa dan menentukan bucket Cloud Storage. Fungsi Anda akan dipanggil setiap kali terjadi perubahan pada objek (file) di dalam bucket yang ditentukan.
Jenis peristiwa Cloud Storage berikut ini didukung:
Acara
Jenis peristiwa
Deskripsi
Objek diselesaikan
google.storage.object.finalize
Terjadi saat objek baru dibuat, atau objek yang ada ditimpa dan pembuatan baru objek tersebut dibuat.
Objek telah dihapus
google.storage.object.delete
Terjadi saat objek dihapus sementara. Untuk mengetahui informasi selengkapnya, lihat
Penghapusan sementara.
Objek diarsipkan
google.storage.object.archive
Terjadi saat versi aktif sebuah objek menjadi versi lama.
Untuk mengetahui informasi selengkapnya, lihat
Pembuatan Versi Objek.
Metadata objek diperbarui
google.storage.object.metadataUpdate
Dikirim saat terjadi perubahan terhadap metadata objek yang ada.
Agar fungsi dapat menggunakan pemicu Cloud Storage, pemicu harus diimplementasikan sebagai fungsi yang dipicu peristiwa:
Jika Anda menggunakan
fungsi latar belakang,
payload data peristiwa Cloud Storage akan diteruskan langsung ke fungsi Anda dalam format
StorageObjectData.
Repositori Google Events berisi resource tambahan untuk menangani data peristiwa.
Deployment
Anda dapat menentukan pemicu Cloud Storage saat men-deploy fungsi. Lihat
Men-deploy fungsi Cloud Run untuk
mengetahui petunjuk umum tentang cara men-deploy fungsi, dan lihat informasi tambahan berikut untuk mengetahui informasi tambahan khusus terkait cara mengonfigurasi pemicu Cloud Storage selama deployment.
gcloud
Jika akan men-deploy menggunakan gcloud CLI, Anda dapat menggunakan jenis peristiwa Object completed Cloud Storage dengan flag berikut:
Flag --trigger-bucket menentukan bucket Cloud Storage yang akan dipantau oleh pemicu.
Peristiwa Objek diselesaikan dalam bucket ini akan memicu panggilan ke fungsi Anda.
Jenis peristiwa ini didukung untuk fungsi lama yang telah menggunakan peristiwa ini. Namun, sebaiknya jangan gunakan jenis peristiwa ini karena mungkin akan dihapus pada tanggal yang akan datang.
Di kolom Bucket, klik Telusuri untuk memilih bucket Cloud Storage yang akan dipantau oleh pemicu. Perubahan pada objek dalam bucket ini akan memicu panggilan ke fungsi Anda.
Centang atau hapus centang pada kotak Coba lagi saat gagal untuk mengontrol
apakah panggilan fungsi yang gagal akan dicoba ulang secara otomatis. Lihat
Mencoba ulang fungsi berbasis peristiwa
untuk mengetahui informasi selengkapnya.
Bucket Cloud Storage dapat memiliki hingga 10 konfigurasi notifikasi yang ditetapkan untuk dipicu untuk peristiwa tertentu. Melebihi batas notifikasi bucket akan menyebabkan deployment fungsi lebih lanjut gagal dengan error seperti berikut:
Anda dapat mengatasi batasan ini dengan
mengelola topik Pub/Sub Anda sendiri
dan mendaftarkannya untuk notifikasi Cloud Storage jenis yang ingin direspons oleh
fungsi Anda. Misalnya, Anda dapat mengonfigurasi satu notifikasi untuk peristiwa yang Anda pilih (seperti pembuatan objek) ke topik Pub/Sub.
Kemudian, miliki sebanyak mungkin pelanggan fungsi yang diperlukan untuk topik guna memproses peristiwa
dan menyebarkannya ke beberapa tujuan. Contoh:
Buat satu konfigurasi notifikasi di bucket Cloud Storage Anda yang dipicu pada peristiwa tertentu (seperti OBJECT_FINALIZE untuk pembuatan objek) dan mengirimkan peristiwa tersebut ke satu topik Pub/Sub Anda.
Buat fungsi (atau fungsi) yang dipicu oleh
topik Pub/Sub.
Lihat Kuota dan batas Cloud Storage untuk mempelajari lebih lanjut batasan Cloud Storage.
[[["Mudah dipahami","easyToUnderstand","thumb-up"],["Memecahkan masalah saya","solvedMyProblem","thumb-up"],["Lainnya","otherUp","thumb-up"]],[["Sulit dipahami","hardToUnderstand","thumb-down"],["Informasi atau kode contoh salah","incorrectInformationOrSampleCode","thumb-down"],["Informasi/contoh yang saya butuhkan tidak ada","missingTheInformationSamplesINeed","thumb-down"],["Masalah terjemahan","translationIssue","thumb-down"],["Lainnya","otherDown","thumb-down"]],["Terakhir diperbarui pada 2025-08-19 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."]]