This page describes the concept of events in the context of Google Cloud Functions. It also covers how to create and associate triggers with functions so that they will execute when an event is fired.
Events are things that happen within your cloud environment that you might want to take action on. These might be changes to data in a database, files added to a storage system, or a new virtual machine instance being created. Currently, Cloud Functions supports events from the following providers:
- Cloud Storage
- Cloud Pub/Sub
- Cloud Firestore
- Firebase (Realtime Database, Storage, Analytics, Auth)
- Stackdriver Logging—forward log entries to a Pub/Sub topic by creating a sink. You can then trigger the function.
For examples of how to associate triggers with functions so that they execute when an event is fired, see the tutorials.
When an event triggers the execution of your Cloud Function, data associated with the event is passed via the function's parameters. The type of event determines the parameters passed to your function. HTTP request events trigger HTTP functions, and the other event types trigger background functions.
In the Node.js 8 and Node.js 10 runtimes, functions take the following parameters:
Node.js 6 (Deprecated)
In the Node.js 6 runtime, functions take the following parameters:
In the Python runtime, functions take the following parameters:
Your function is passed a single parameter,
(request), which is a Flask
Requestobject. Return any value from your function that can be handled by the Flask
make_responsemethod. The result will be the HTTP response.
Your function is passed the parameters
(data, context). See Background Functions for more details on these parameters.
In the Go runtime, functions take the following parameters:
Creating a response to an event is done with a trigger. A trigger is a declaration that you are interested in a certain event or set of events. Binding a function to a trigger allows you to capture and act on events.
Below is a table of the types of triggers supported and the flags used to specify them during command-line deployment:
|Google Cloud Pub/Sub||
|Other sources (e.g. Firebase)||
For more information on the command-line flags, see the
gcloud functions deploy reference.
Binding of triggers to functions happens at deployment time either via the gcloud command-line tool, the UI or Cloud Functions API. Functions and triggers are bound to each other on a many-to-one basis. In other words, you cannot bind the same function to more than a single trigger at a time. You can, however, have the same trigger cause multiple functions to execute by simply deploying two different functions with the same trigger.