Cloud Run functions triggers (1st gen)

You can set up Cloud Run functions to execute in response to various scenarios by specifying a trigger for your function. Triggers can be HTTP(S) requests or one of a number of supported events. This page provides an overview of the triggers supported by Cloud Run functions.

Broadly, triggers fall into two categories:

  • HTTP triggers, which react to HTTP(S) requests, and correspond to HTTP functions.

  • Event triggers, which react to events within your Google Cloud project, and correspond to event-driven functions.

You specify triggers as part of function deployment. You cannot bind the same function to more than one trigger at a time, but you can have the same event cause multiple functions to execute by deploying multiple functions with the same trigger settings.

Supported triggers

Cloud Run functions supports the following types of triggers:

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 Logging

Cloud Logging can route logs to a Pub/Sub topic, where they can then be consumed by Cloud Run functions. See Configure and manage sinks in the Cloud Logging documentation for more information.

Cloud Scheduler

Cloud Scheduler jobs can send messages to a Pub/Sub topic, where they can then be consumed by Cloud Run functions. See the Cloud Scheduler tutorial Using Pub/Sub to trigger a Cloud Run function for more information.

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.

Trigger permissions

Cloud Run functions (1st gen) configures the event trigger on your behalf. When you deploy an event-driven function, IAM checks whether you can create or update the function and act as its service account. It doesn't check whether you, or the function's service account, can read the event source itself. For example, a principal who can't read a Cloud Storage bucket can still deploy a function that receives an event, including the object metadata, every time an object is created in that bucket.

When you create or update an event-driven Cloud Run function (1st gen), IAM checks the following:

  • You have cloudfunctions.functions.create or cloudfunctions.functions.update on the Google Cloud project.
  • You have iam.serviceAccounts.actAs on the function's service accounts.

IAM doesn't check whether you or the function's service account have any permissions on the event source resource, such as the bucket, topic, or database that emits the events.

To help limit this risk, do all of the following:

  • Treat cloudfunctions.functions.create or cloudfunctions.functions.update combined with iam.serviceAccounts.actAs as equivalent to read access to every event source in the Google Cloud project. Grant roles that include these permissions only to principals that you would trust to read that data directly.
  • Restrict iam.serviceAccounts.actAs on all service accounts in the Google Cloud project, including the default service accounts.
  • If some principals must be able to deploy functions but must not see data from a particular event source, keep that event source in a separate Google Cloud project, or don't use Cloud Run functions (1st gen) in the Google Cloud project that contains the event source.