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?
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.