You are currently viewing How To Configure PubSub Notifications for Cloud Storage

How To Configure PubSub Notifications for Cloud Storage

How To Configure PubSub Notifications In Cloud Storage

Hello Everyone

Welcome to CloudAffaire and this is Debjeet.

In the last blog post, we have discussed Object Lifecycle Management in Cloud Storage.

In this blog post, we will discuss how to configure PubSub Notification in Cloud Storage.

PubSub Notifications for Cloud Storage:

PubSub Notifications sends information about changes to objects in your buckets to PubSub, where the information is added to a PubSub topic of your choice in the form of messages. For example, you can track objects that are created and deleted in your bucket. Each notification contains information describing both the event that triggered it and the object that changed.

You can send notifications to any PubSub topic in any project for which you have sufficient permissions. Once received by the PubSub topic, the resulting message can be sent to any number of subscribers to the topic.

Notification configurations:

A notification configuration is a rule you attach to a bucket that specifies:

  • The topic in PubSub that receives notifications.
  • The events that trigger a notification to be sent.
  • The information contained within notifications.

You can attach multiple notification configurations to a bucket. A bucket can have up to 100 total notification configurations and up to 10 notification configurations set to trigger for a specific event.

Each notification configuration is identified by an integer. This integer is returned:

  • When you create the notification configuration.
  • When you list the notification configurations attached to a bucket.
  • In the notificationConfig attribute of each notification triggered by the notification configuration.

Creating and deleting notification configurations increment a bucket’s metageneration number.

Event types:

The following is a list of event types currently supported by Cloud Storage:

  • OBJECT_FINALIZE: Sent when a new object (or a new generation of an existing object) is successfully created in the bucket. This includes copying or rewriting an existing object.
  • OBJECT_METADATA_UPDATE: Sent when the metadata of an existing object changes.
  • OBJECT_DELETE: Sent when an object has been permanently deleted. This includes objects that are overwritten or are deleted as part of the bucket’s lifecycle configuration.
  • OBJECT_ARCHIVE: Only sent when a bucket has enabled object versioning. This event indicates that the live version of an object has become a noncurrent version

Notification format:

Notifications sent to the PubSub topic consist of two parts:

  • Attributes: A set of key:value pairs describing the event.
  • Payload: A string that contains the metadata of the changed object.

Delivery guarantees:

When you add a notification configuration, Cloud Storage may take up to 30 seconds to begin sending notifications associated with it. Once started, Cloud Storage guarantees at-least-once delivery to PubSub. PubSub also offers at-least-once delivery to the recipient, which means that you could receive multiple messages, with multiple IDs, that represent the same Cloud Storage event.

Notifications are not guaranteed to be published in the order PubSub receives them. If you plan to modify the Cloud Storage object based on a notification, it is recommended that you use the object’s generation and metageneration numbers as preconditions on your update request. If a notification consistently cannot be delivered to a PubSub topic, Cloud Storage may delete the notification after 7 days. Delivery failure can occur when the PubSub topic no longer exists, when Cloud Storage no longer has permission to publish to the topic, or when the project that owns the topic exceeds its publishing quota.

How To Configure PubSub Notifications In Cloud Storage:

Step 1: Enable PubSub API for your project.

Step 2: Create a Topic and Subscription in your PubSub.

Step 3: Create a bucket in Cloud Storage.

Step 4: Create a PubSub Notification Configuration for your bucket.

Step 5: PubSub Notifications for Cloud Storage.

Step 6: Cleanup.

Hope you have enjoyed this article. In the next blog post, we will discuss object metadata in cloud storage.

All the public cloud providers are changing the console user interface rapidly and due to this some of the screenshots used in our previous AWS blogs are no longer relevant. Hence, we have decided that from now onwards most of the demo will be done programmatically. Let us know your feedback on this in the comment section.

To get more details on cloud storage, please refer below GCP documentation.


Leave a Reply