2
votes

I was trying to create a google cloud function which can be triggered by a pubsub topic. I used the google deployment manager template for creating it. But I couldn't find any way to set the subscriber message filter for that cloud function. I tried to create the subscription before and after the cloud function resource was created. But in no ways it worked. If I create it before creating cloud function then after the resource is created it overrides the subscriber function and removes the filter.

Is it possible to set subscriber message filter for any pubsub cloud function using google deployment manager template?

1

1 Answers

4
votes

In fact, it's not possible at all. When you deploy a Cloud functions in mode trigger-topic, you can't set a filter on the subscription (which is automatically created). And it's not a limitation of deployment manager.

If you want to trigger a Cloud Function on a PubSub message with the filter activated, you need to

  • Deploy your function in HTTP mode (trigger-http)
  • Create a Push Subscription to call in HTTP the Cloud Functions with the message in parameter. When you create the Push Subscription, this time, you can set the filter that you want
  • Secure the communication between the Push Subscription and the Cloud Functions (the security is automatically built in the trigger-topic mode (alias background function))