Mantenha tudo organizado com as coleções
Salve e categorize o conteúdo com base nas suas preferências.
Gatilhos do Cloud Storage (1ª geração)
No Cloud Run functions, um acionador do Cloud Storage permite que uma função seja chamada
em resposta às mudanças no Cloud Storage. Ao especificar um gatilho do Cloud Storage para uma função, você escolhe um tipo de evento e um bucket do Cloud Storage. A função será chamada sempre que ocorrer uma alteração em um objeto (arquivo) no bucket especificado.
Os seguintes tipos de eventos do Cloud Storage são compatíveis:
Evento
Tipo de evento
Descrição
Objeto finalizado
google.storage.object.finalize
Isso ocorre quando um novo objeto é criado ou
um objeto existente é substituído e uma nova geração desse objeto é criada.
Objeto excluído
google.storage.object.delete
Isso ocorre quando um objeto é excluído permanentemente.
Objeto arquivado
google.storage.object.archive
Isso ocorre quando uma versão ativa de um objeto se torna uma versão não atual.
Consulte Controle de versão de objeto
para mais informações.
Metadados de objetos atualizados
google.storage.object.metadataUpdate
Ocorre quando os metadados de um objeto são alterados.
Para que uma função use um acionador do Cloud Storage, ela precisa ser implementada como uma
função orientada a eventos:
Se você usar uma função em segundo plano, o payload de dados de eventos do Cloud Storage será transmitido diretamente para sua função no formato StorageObjectData.
O repositório
Eventos do Google
contém outros recursos para trabalhar com dados de eventos.
Implantação
É possível especificar um acionador do Cloud Storage ao implantar uma função. Consulte
Implantar uma função do Cloud Run
para instruções gerais sobre como implantar uma função. Confira abaixo
mais informações específicas para configurar gatilhos do Cloud Storage durante a implantação.
gcloud
Se você estiver implantando usando a CLI gcloud, poderá usar o tipo de evento Objeto finalizado do Cloud Storage com as seguintes sinalizações:
A flag --trigger-bucket especifica o bucket do Cloud Storage que será monitorado pelo gatilho.
Eventos finalizados pelo objeto nesse bucket acionarão chamadas para sua função.
Esse tipo de evento é compatível com funções legadas que já consomem
esses eventos. No entanto, não recomendamos usar esse tipo de evento, porque ele pode ser
removido em uma data futura.
No campo tipo de Acionador, selecione Cloud Storage.
No campo Tipo de evento, selecione um tipo.
No campo Bucket, clique em Procurar para selecionar um
bucket do Cloud Storage para o gatilho monitorar. As alterações feitas nos
objetos dentro desse bucket acionarão chamadas para sua função.
Marque ou desmarque a caixa de seleção Tentar novamente em caso de falha para controlar
se novas tentativas são feitas automaticamente. Consulte
Como repetir funções orientadas a eventos
para mais informações.
Um bucket do Cloud Storage pode ter até 10 configurações de notificação definidas para gatilho de um evento específico. Exceder os limites de notificações do bucket fará com que outras implantações de função falhem com um erro como este:
[[["Fácil de entender","easyToUnderstand","thumb-up"],["Meu problema foi resolvido","solvedMyProblem","thumb-up"],["Outro","otherUp","thumb-up"]],[["Difícil de entender","hardToUnderstand","thumb-down"],["Informações incorretas ou exemplo de código","incorrectInformationOrSampleCode","thumb-down"],["Não contém as informações/amostras de que eu preciso","missingTheInformationSamplesINeed","thumb-down"],["Problema na tradução","translationIssue","thumb-down"],["Outro","otherDown","thumb-down"]],["Última atualização 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."]]