Cloud Run functions triggers
When you deploy or update a function created with the Cloud Functions API (v2), you have access to all of Cloud Run's configuration capabilities.
There are two ways to trigger functions:
When you create functions with the Cloud Functions API (v2), you specify triggers as part of function deployment.
When you create functions with the Cloud Run Admin API, you can use Eventarc, Pub/Sub, or other HTTP triggers to trigger the function.
Use this page to understand the different types of triggers you can configure for your functions. See Cloud Run documentation for a full list of supported triggers.
Types of trigger
You can set up your function to execute in response to various scenarios by configuring a trigger. Configure HTTP triggers for HTTP functions and event triggers for CloudEvents functions.
HTTP triggers
HTTP triggers react to HTTP(S) requests, and correspond to HTTP functions. For more information about writing HTTP functions, see Write HTTP functions.
When you create a function with the Cloud Functions API (v2), by default, the
function has an HTTP endpoint URL cloudfunctions.net
. If you take this
function and deploy it on Cloud Run, your function also receives an
run.app
URL. However, functions created in Cloud Run won't have an
cloudfunctions.net
HTTP endpoint URL. A function's cloudfunctions.net
URL
and run.app
URL will behave in exactly the same way. They are interchangeable,
and are used to trigger your function.
For more information about invoking a function with an HTTP trigger, see Invoke with an HTTPS Request.
Event triggers
Event triggers react to events within your Google Cloud project, and correspond to event-driven functions (also known as CloudEvents functions). For more information about writing event-driven functions, see Write CloudEvents functions. For more information about invoking your function in response to event triggers, see Create triggers with Eventarc.
All event-driven functions use Eventarc for event delivery. Pub/Sub triggers and Cloud Storage triggers are implemented as particular types of Eventarc triggers.
This section describes some examples of event triggers that Cloud Run functions supports.
Pub/Sub triggers
You can trigger your function in response to Pub/Sub messages using Eventarc. When you specify a Pub/Sub trigger for your function, you also specify a Pub/Sub topic. As a result of this trigger, your function is called whenever you publish a message to the specified topic. For more information, see Pub/Sub triggers.
You can also use Cloud Logging to route logs to a Pub/Sub topic, to be consumed by Cloud Run functions. For more information, see Trigger functions from log entries.
Cloud Storage triggers
You can trigger your function from Cloud Storage using Eventarc, in response to changes in Cloud Storage. When you specify a Cloud Storage trigger for your function, you choose an event type and specify a Cloud Storage bucket. As a result of this trigger, your function is called whenever a change occurs on an object (file) within the specified bucket. For more information, see Cloud Storage triggers.
Firestore triggers
You can configure your Cloud Run functions to be triggered by events in a Firestore database. When triggered, your function reads and updates a Firestore database in response to these events through the Firestore APIs and client libraries. For more information, see Firestore triggers.
Other event triggers
Cloud Run functions supports any event type supported by Eventarc, including 90+ event sources via Cloud Audit Logs.
Additional triggers via Pub/Sub and webhooks
Because Cloud Run functions can be triggered by messages on a Pub/Sub topic, you can integrate Cloud Run functions with any other Google service that supports Pub/Sub as an event bus. In addition, by using HTTP triggers you can also integrate with any service that provides HTTP callbacks (webhooks). The following sections describe some example integrations.
Cloud Scheduler
You can trigger a function with an HTTP trigger or an event trigger.
To schedule an HTTP Cloud Run function, create a Cloud Scheduler job that triggers an action using HTTP. You can also schedule an event-driven function that gets triggered directly in response to events within your Google Cloud project; for example, when a message is published to a Pub/Sub topic.
For more information, see About Cloud Scheduler.
Cloud Tasks
Cloud Tasks HTTP Target tasks enable you to run task handlers at any HTTP endpoint, so a Cloud Run function with an HTTP trigger can be used as a task handler. You can also use tasks to throttle or rate-limit function invocations. See Create HTTP Target tasks in the Cloud Tasks documentation for more information.
Gmail
Using the Gmail Push Notification API, you can send Gmail events to a Pub/Sub topic and consume them with Cloud Run functions.