Get startedGet started for free

Triggering functions

1. Triggering functions

In this module, we’ll discuss how you can call Cloud Run functions with function triggers. You will learn about the different types of function triggers and how to use them when deploying your functions. We will also discuss how to connect Cloud Run functions to Virtual Private Cloud (VPC) networks within your cloud infrastructure. Finally, we will review connecting Cloud Run functions with workflows. We’ll first discuss Cloud Run functions triggers, then how to connect Cloud Run functions with workflows, and how to connect Cloud Run functions to resources in a VPC network. You can then put this in practice by completing an optional lab to connect Cloud Run functions to resources in a VPC network. Finally, we’ll review the topics that were discussed in this module. Let’s get started with Cloud Run functions triggers. You 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 several supported cloud events. There are two categories of triggers: HTTP triggers, which react to HTTP(S) requests, and correspond to HTTP functions, and 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 can have the same event cause multiple functions to execute by deploying multiple functions with the same trigger source settings. But, you cannot bind the same function to more than one trigger at a time. With event-driven Cloud Run functions, you can create Eventarc event triggers using filters. Event filters can include the service name, method name, event type, and other information. You can create triggers with the correct event filters in the Google Cloud console or with the gcloud CLI. All event driven Cloud Run functions use Eventarc for event delivery. Eventarc supports more than 90 Google Cloud sources, including events from Cloud Audit Logs, external SaaS event sources, and custom sources by publishing to Pub/Sub. You can integrate Cloud Run functions with any other Google service that supports Pub/Sub as an event bus, for example Cloud Logging and Cloud Scheduler. This is possible because Cloud Run functions can be triggered by messages on a Pub/Sub topic. You can also use HTTP Cloud Run functions as task handlers with Cloud Tasks. Using the Gmail Push Notification API, you can send Gmail events to a Pub/Sub topic and consume them with Cloud Run functions. HTTP triggers enable a function to run in response to HTTP(S) requests. When you specify an HTTP trigger for a function, the function is assigned a URL at which it can receive requests. Cloud Run functions are assigned an HTTPS endpoint at which they can be invoked. HTTP triggers support the GET, POST, PUT, DELETE, and OPTIONS request methods. Pub/Sub triggers enable functions to be called in response to Pub/Sub messages. When you specify a Pub/Sub trigger for a function, you also specify a Pub/Sub topic. Your function will be called whenever a message is published to the specified topic. For a function to use a Pub/Sub trigger, it must be implemented as an event-driven function. If a CloudEvent function is used, the Pub/Sub event data is passed to the function in the CloudEvents format. If a Background function is used, the Pub/Sub event data is passed to function in the PubsubMessage format. In Cloud Run functions, Pub/Sub triggers are implemented as a type of Eventarc trigger. Cloud Storage triggers enable functions to be called in response to changes in Cloud Storage. When you specify a Cloud Storage trigger for a function, you choose an event type and provide a specific Cloud Storage bucket. The function will be called whenever a change occurs on an object (file) within the specified bucket. For a function to use a Cloud Storage trigger, it must be implemented as an event-driven function. If a CloudEvent function is used, the Cloud Storage event data is passed to the function in the CloudEvents format. If a Background function is used, the Cloud Storage event data is passed to the function in the StorageObjectData format. In Cloud Run functions, Cloud Storage triggers are implemented as a type of Eventarc trigger. Firestore triggers enable functions to handle events in Firestore that is in the same Google Cloud project as the function. When you specify a Firestore trigger for a function, you choose an event type, and a document path. When an event of the specified type occurs on a document, the function is invoked. Firestore supports create, update, delete, and write events. The function receives a data object with a snapshot of the affected document. Firestore triggers only apply at the document level. It is not possible to create a trigger for a specific document field or collection. Firestore must be in the same Google Cloud project as the function. The function can be a CloudEvent or Background function based on the language runtime. Cloud Run fnctions supports triggers for various Firebase services: Google Analytics for Firebase (Cloud Run functions 1st generation only), Firebase Realtime Database, Firebase Authentication (Cloud Run functions 1st generation only) And Firebase Remote Config. You can handle events in the Firebase service that is in the same Google Cloud project as the function.

2. Let's practice!

Create Your Free Account

or

By continuing, you accept our Terms of Use, our Privacy Policy and that your data is stored in the USA.