Pravin Maske
Pravin Maske

Reputation: 53

Is it possible to create a Pub/Sub Cloud Storage notification for Bucket which resides in another project?

Background: I've Cloud Storage bucket in Project A and All other compute services in Compute Project B.

The requirement is to create a Cloud Function and Pub/Sub Notification in Storage project B.

Steps in plan are:

  1. Create a Pub/Sub cloud storage notification in Project B for the Storage Bucket which resides in Project A (If any new object gets created in bucket then the storage event needs to be sent to Topic present in Project B)
  2. Once we receive the storage event in Project B then the same should be sent to Cloud Function via another Subscription which will trigger the Cloud Function with storage event information.
  3. Need to use Storage event for further in Cloud Function

Q: Is it possible to create storage notification from Project B for Cloud storage residing in Project A? How can we do that ? Also I want to have this event to be sent to Cloud Function later, how can we do that ?

Appreciate your help!!

Upvotes: 1

Views: 1150

Answers (1)

Brandon Yarbrough
Brandon Yarbrough

Reputation: 38369

Yes, you can! It works the same as setting it up within one project, but you need to specify the project IDs.

  1. Create the bucket in project A: gsutil mb -p project-a -l location gs://bucket-name
  2. Create the notification in project B: gcloud pubsub topics create projects/project-b/topics/topic-name
  3. Configure notifications:
# Assuming here that caller has permissions to both projects.
gsutil notification create \
         -f json \
         -t projects/project-b/topics/topic-name \
         gs://bucket-name
  1. Set up a cloud function to trigger on your topic either via gcloud or from the UI: https://cloud.google.com/functions/docs/calling/pubsub#gcloud

Upvotes: 4

Related Questions