List Pub/Sub notifications

Stay organized with collections Save and categorize content based on your preferences.

List the Pub/Sub notifications set up for a Cloud Storage storage bucket.

Explore further

For detailed documentation that includes this code sample, see the following:

Code sample


For more information, see the Cloud Storage C++ API reference documentation.

namespace gcs = ::google::cloud::storage;
using ::google::cloud::StatusOr;
[](gcs::Client client, std::string const& bucket_name) {
  StatusOr<std::vector<gcs::NotificationMetadata>> items =
  if (!items) throw std::move(items).status();

  std::cout << "Notifications for bucket=" << bucket_name << "\n";
  for (gcs::NotificationMetadata const& notification : *items) {
    std::cout << notification << "\n";


For more information, see the Cloud Storage C# API reference documentation.

using Google.Apis.Storage.v1.Data;
using Google.Cloud.Storage.V1;
using System;
using System.Collections.Generic;

public class ListPubSubNotificationSample
    public IReadOnlyList<Notification> ListPubSubNotification(string bucketName = "your-unique-bucket-name")
        StorageClient storage = StorageClient.Create();
        IReadOnlyList<Notification> notifications = storage.ListNotifications(bucketName);

        foreach (Notification notification in notifications)
        return notifications;


For more information, see the Cloud Storage Go API reference documentation.

import (


// listBucketNotifications lists notification configurations for a bucket.
func listBucketNotifications(w io.Writer, bucketName string) error {
	// bucketName := "bucket-name"

	ctx := context.Background()
	client, err := storage.NewClient(ctx)
	if err != nil {
		return fmt.Errorf("storage.NewClient: %v", err)
	defer client.Close()

	notifications, err := client.Bucket(bucketName).Notifications(ctx)
	if err != nil {
		return fmt.Errorf("Bucket.Notifications: %v", err)

	for nID, n := range notifications {
		fmt.Fprintf(w, "Notification topic %s with ID %s\n", n.TopicID, nID)

	return nil


For more information, see the Cloud Storage Java API reference documentation.

import java.util.List;

public class ListPubSubNotifications {

  public static void listPubSubNotifications(String bucketName) {
    // The ID to give your GCS bucket
    // String bucketName = "your-unique-bucket-name";

    Storage storage = StorageOptions.newBuilder().build().getService();
    List<Notification> notificationList = storage.listNotifications(bucketName);
    for (Notification notification : notificationList) {
          "Found notification " + notification.getTopic() + " for bucket " + bucketName);


For more information, see the Cloud Storage Node.js API reference documentation.

 * TODO(developer): Uncomment the following lines before running the sample.
// The ID of your GCS bucket
// const bucketName = 'your-unique-bucket-name';

// Imports the Google Cloud client library
const {Storage} = require('@google-cloud/storage');

// Creates a client
const storage = new Storage();

async function listNotifications() {
  // Lists notifications in the bucket
  const [notifications] = await storage.bucket(bucketName).getNotifications();

  notifications.forEach(notification => {



For more information, see the Cloud Storage PHP API reference documentation.

use Google\Cloud\Storage\StorageClient;

 * Lists notification configurations for a bucket.
 * This sample is used on this page:
 * @param string $bucketName The name of your Cloud Storage bucket.
 *        (e.g. 'your-bucket')
function list_bucket_notifications(
    string $bucketName
): void {
    $storage = new StorageClient();
    $bucket = $storage->bucket($bucketName);
    $notifications = $bucket->notifications();

    foreach ($notifications as $notification) {
        printf('Found notification with id %s' . PHP_EOL, $notification->id());
        'Listed %s notifications of storage bucket %s.' . PHP_EOL,


For more information, see the Cloud Storage Python API reference documentation.

from import storage

def list_bucket_notifications(bucket_name):
    """Lists notification configurations for a bucket."""
    # The ID of your GCS bucket
    # bucket_name = "your-bucket-name"

    storage_client = storage.Client()
    bucket = storage_client.bucket(bucket_name)
    notifications = bucket.list_notifications()

    for notification in notifications:
        print(f"Notification ID: {notification.notification_id}")


For more information, see the Cloud Storage Ruby API reference documentation.

require "google/cloud/storage"

def list_bucket_notifications bucket_name:
  # The ID of your GCS bucket
  # bucket_name = "your-unique-bucket-name"

  storage =
  bucket  = storage.bucket bucket_name

  bucket.notifications.each do |notification|
    puts "Notification ID: #{}"

What's next

To search and filter code samples for other Google Cloud products, see the Google Cloud sample browser.