Deploying a background function in a project B, triggered by a pubsub topic from project A

860 views
Skip to first unread message

Jean-Baptiste Claramonte

unread,
Aug 22, 2018, 9:01:57 AM8/22/18
to Google Cloud Pub/Sub Discussions
Hello

It's possible to create a topic "my-topic-project-a" in project "project-a" so that it can be publicly visible (this is done by setting the role "pub/sub subscriber" to "allUsers" on it).
Then from project "project-b" I can create a subscription to "my-topic-project-a"  and read the events from "my-topic-project-a". This is done using the following gcloud commands:
(these commands are executed on project "project-b")

gcloud pubsub subscriptions create subscription-to-my-topic-project-a --topic projects/project-a/topics/my-topic-project-a
gcloud pubsub subscriptions pull 
subscription-to-my-topic-project-a --auto-ack

So ok this is possible when creating a subscription in "project-b" linked to "my-topic-project-a" in "project-a".

In my use case I would like to be able to deploy a background Function "myBgFunctionInProjectB" in "project-b" and triggered by my topic "my-topic-project-a" from "project-a"

This doesn't seem to be possible since gcloud CLI is not happy when you provide the full topic name while deploying the cloud function:

gcloud beta functions deploy myBgFunctionInProjectB --runtime nodejs8 --trigger-topic projects/project-a/topics/my-topic-project-a --trigger-event google.pubsub.topic.publish

ERROR: (gcloud.beta.functions.deploy) argument --trigger-topic: Invalid value 'projects/project-a/topics/my-topic-project-a': Topic must contain only Latin letters (lower- or upper-case), digits and the characters - + . _ ~ %. It must start with a letter and be from 3 to 255 characters long.

is there a way to achieve that or this is actually not possible?

Thanks
JB


Tianzi Cai

unread,
Aug 22, 2018, 1:18:36 PM8/22/18
to Google Cloud Pub/Sub Discussions
Hi JB, I wonder if it's just a matter of changing `--trigger-topic` to `--trigger-resource`. Were you following the instructions here

Tianzi Cai

unread,
Aug 22, 2018, 1:32:31 PM8/22/18
to Google Cloud Pub/Sub Discussions
Hmm, it looks like that Google Cloud Functions may not yet support listening to a resource in another project (Stack OverFlow). The suggested workaround is to use a push subscriber instead. 

Jean-Baptiste Claramonte

unread,
Aug 23, 2018, 8:59:57 AM8/23/18
to Google Cloud Pub/Sub Discussions
thanks for your help on this Tianzi
Yes, I also tried to use push subscriber but there seems to be some issue related to domain ownership checking on the cloud function and I didn't actually well understand how to resolve that event with this stack overflow ... :-/ 

Jordan (Cloud Platform Support)

unread,
Aug 23, 2018, 8:09:20 PM8/23/18
to Google Cloud Pub/Sub Discussions
I believe the solution proposed in that Stack Overflow post consists of adding the following code to your function's response:

res.writeHeader(200, {"Content-Type": "text/html"}); 
res.write('<HTML><HEAD><meta name="google-site-verification" content="String_we_ask_for"></HEAD><BODY></HTML>');  
  
Which follows the HTML tag verification processes where you simply return an HTML response containing a "google-site-verification" meta tag with the "String_we_ask_for" provided by the verification steps

- Note that Google Groups is reserved for general product discussions and is not for technical support. For further technical support with getting your function to return a verification meta tag it is recommended to post your detailed questions to Stack Exchange using the supported Cloud tags. 

Jean-Baptiste Claramonte

unread,
Aug 24, 2018, 9:07:06 AM8/24/18
to Google Cloud Pub/Sub Discussions
Thanks
Reply all
Reply to author
Forward
0 new messages