0

I have a Cloud Function (v1) that is set to trigger every time a message is received in a specific topic. This part of the configuration is done correctly (since I've followed previous working cloud functions).

This is my cloud function:

const myCloudFunction = functions.pubsub
  .topic("myTopic")
  .onPublish(async (message) => {
    // do something
  });

I've had some problems with the topic configuration but now everything seems to be working (the service account have the permissions it should have to manage the messages and the topic is receiving and processing them properly).

Now it's where it gets a little confusing to me: as far as I understand, every time a message is published in a topic, the subscription need to publish this message to the service that it's consuming (in this case, cloud functions).

The subscription is also receiving the message but the CF is not being triggered. After some research, I've discovered that I need to change the delivery type from PULL (that requires an active trigger - which we don't want to) to PUSH. However, this PUSH configuration ask's me an Endpoint URL, and I didn't understand where should I get this not only from the working ones, but neither in the documentation. Should this be from the cloud function, the topic or somewhere else? How can I find it?

Screenshot from Google Pub/Sub Delivery Type selection with "Push" option selected, a text box with "Endpoint URL" is displayed with red outline and and error "Endpoint URL is required for push subscriptions."

1
  • It's the Cloud Function's URL, yeah. It should have been exposed as you created the Cloud Function. There may be a higher level way to set it up though, where you don't have to work with the URL manually. That's why I'll leave this as just a comment for now, not an answer. It would be nice to get a thorough answer from someone who uses these technologies regularly who can recommend the simplest way to accomplish your goal (link topic to function). My knowledge is a bit rusty since it's been a few years since I've set something like this up.
    – Matt Welke
    Commented 23 hours ago

1 Answer 1

0

As far as I know you don’t need to manually create or configure a PUSH subscription for a standard Cloud Function v1 Pub/Sub trigger. When you define a Cloud Function triggered by a Pub/Sub topic using functions.pubsub.topic("myTopic").onPublish(...) , Google Cloud automatically creates a subscription for you. The Cloud Function is inherently set up to act like a push endpoint, so you don't need to manually create a push subscription or provide an endpoint URL. The Cloud Function itself is the endpoint. The Pub/Sub service knows to send messages to your function when they are published to the topic.

Just ensure the service account has the necessary permissions to trigger the Cloud Function.

Also sharing this case that might be helpful to you.

1
  • Let me know if this has resolved your issue. If it did, an upvote or marking it as accepted would be appreciated as this helps the community.
    – jggp1094
    Commented 7 hours ago

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.