Triggering Cloud Run functions
You set a Cloud Run function to run in response to something by giving it a trigger when you deploy it. Triggers come in two categories: an HTTP trigger (reacts to HTTP(S) requests, backs an HTTP function) and an event trigger (reacts to an event in your Google Cloud project, backs an event-driven function). This page covers how triggers are specified, which sources are supported, and the shape of each trigger type.
Specifying triggers
- Triggers are specified as part of function deployment.
- The same event can invoke multiple functions - deploy several functions with the same trigger source settings.
- For event-driven functions, you create Eventarc event triggers using filters. A filter can match the service name, method name, event type, and other information. Create them in the Google Cloud console or with the gcloud CLI.
A function cannot be bound to more than one trigger at a time. Fan-out is fine (one trigger source can drive many functions), but the reverse is not - a single function has exactly one trigger.
Supported triggers
All event-driven Cloud Run functions use Eventarc for event delivery. Eventarc supports 90+ Google Cloud sources, including events from Cloud Audit Logs, external SaaS event sources, and custom sources (by publishing to Pub/Sub).
Because a function can be triggered by messages on a Pub/Sub topic, you can integrate any Google service that uses Pub/Sub as an event bus:
- Cloud Logging and Cloud Scheduler - route their events through Pub/Sub to a function.
- Cloud Tasks - an HTTP Cloud Run function can act as a task handler.
- Gmail - the Gmail Push Notification API sends Gmail events to a Pub/Sub topic, consumed by a function.
HTTP trigger
An HTTP trigger enables a function to run in response to HTTP(S) requests. When assigned, the function gets an HTTPS endpoint (URL) at which it can be invoked.
GET,POST,PUT,DELETE,OPTIONS.
Pub/Sub trigger
- A Pub/Sub topic must be specified. The function is called whenever a message is published to that topic.
- The function must be an event-driven function.
- In Cloud Run functions, a Pub/Sub trigger is implemented as a type of Eventarc trigger.
- Event data is passed in CloudEvents format (for a CloudEvent function) or PubsubMessage format (for a Background function).
Cloud Storage trigger
- You choose an event type and a Cloud Storage bucket. The function is called whenever a change of that type occurs on an object (file) in the bucket.
- The function must be an event-driven function.
- Event data is passed in CloudEvents format or StorageObjectData format.
- Implemented as a type of Eventarc trigger.
- Object finalized - a new object is created (or an overwrite completes).
- Object deleted.
- Object archived.
- Object metadata updated.
For the IAM plumbing a Cloud Storage trigger needs before deploy, see Cloud Storage triggers need IAM plumbing first.
Firestore trigger
- You choose an event type and a document path. The function is invoked when an event of that type occurs on a document, and it receives a snapshot of the affected document.
- Firestore supports create, update, delete, and write events (
onCreate,onUpdate,onDelete,onWrite, where write fires on any of the other three). - The document path can reference a specific document (
users/john) or a wildcard pattern (users/{userId}), and must not contain a trailing slash. - Firestore must be in the same Google Cloud project as the function.
- The function can be a CloudEvent or Background function depending on the language runtime.
Firestore triggers are available only for Firestore in Native mode. They are not available for Firestore in Datastore mode.
A Firestore trigger applies only at the document level. You cannot create a trigger for a specific document field or for a collection.
Firebase triggers
Cloud Run functions supports triggers for several Firebase services. Each uses its own event types and config resources, and the Firebase service must be in the same Google Cloud project as the function.
- Google Analytics for Firebase - 1st generation only.
- Firebase Realtime Database.
- Firebase Authentication - 1st generation only.
- Firebase Remote Config.
Google Analytics for Firebase and Firebase Authentication triggers are supported only on 1st-generation Cloud Run functions - they are not available on 2nd-gen functions.