Google Cloud Storage Triggers | Cloud Functions Documentation

Cloud Functions usesevent-driven functions tohandle events from your Cloud infrastructure.For example, Cloud Functions can respond to change notifications emerging fromGoogle Cloud Storage. These notifications can be configured totrigger in response to various events inside a bucketobject creation, deletion,archiving and metadata updates.

Cloud Storage events used by Cloud Functions are based onCloud Pub/Sub Notifications for Google Cloud Storageand are provided in the Cloud Storage JSON API format.

Storage-triggered functions support four trigger types. These trigger typevalues are used upon function deployment to specify which Cloud Storage eventswill trigger your functions:

The following sample function logs relevant data when an event occurs.

You specify the trigger type when you deploy the function. For example,the deployment example below uses the function to log every timean object is created by specifying the google.storage.object.finalizetrigger type.

For a full tutorial on running this code, see theCloud storage tutorial:

The following gcloud command deploys the function with an object.finalizetrigger.

where YOUR_TRIGGER_BUCKET_NAME is the name of the CloudStorage bucket that the function will monitor.

Trigger type value: google.storage.object.finalize

This event is sent when a new object is created (or an existing object isoverwritten, and a new generation of that object is created) in the bucket.

Trigger type value: google.storage.object.delete

This event is sent when an object is permanently deleted. Depending on theobject versioning setting for a bucket thismeans:

For versioning buckets, this is only sent when a version is permanentlydeleted (but not when an object is archived).

For non-versioning buckets, this is sent when an object is deleted oroverwritten.

Trigger type value: google.storage.object.archive

This event is sent when alive version of an object is archived ordeleted.

This event is only sent for versioning buckets.

Trigger type value: google.storage.object.metadataUpdate

This event is sent when the metadataof an existing object changes.

Storage event data is delivered in the Cloud Storage objectformat.

Events are delivered usingPub/Sub notifications from Cloud Storage.Events are subject to Pub/Sub's delivery guarantees.

A bucket can have up to 10 notification configurations set to trigger for aspecific event. Setting up too many notifications for the same bucket mightexceed the notifications limit for the bucket and make it impossible to createthe function, as indicated by the following error:

If you reach the limit, you can't create a function until you take remedialaction, such as removing notifications.

Learn more about the quotas and request limits forCloud Storage.

You must have sufficient permissions on the project that will receivenotifications. This includes ensuring that you do the following:

Get the email address of the service agent associated withthe project that contains your Cloud Storage bucket.

Use the email address that you obtained in the previous step togive the service agent the IAM role pubsub.publisher for therelevant Pub/Sub topic.

Learn more aboutconfiguring Pub/Sub notificationsfor Cloud Storage.

The gcloud command below deploys a function that is triggered by legacyobject change notifications on aspecific bucket. Generally, Cloud Pub/Sub notifications areeasier to use, more flexible, and more powerful than object change notifications.However, these legacy notifications are supported for legacy functions alreadyconsuming these events.

See the Cloud Storage Tutorial for an example of how toimplement an event-driven function that is triggered by Cloud Storage.

Follow this link:
Google Cloud Storage Triggers | Cloud Functions Documentation

Related Posts

Comments are closed.