Events and Triggers

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

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:

For examples of how to associate triggers with functions so that they execute
when an event is fired, see the tutorials.

Event data

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.

Node.js 8/10

In the Node.js 8 and Node.js 10 runtimes, functions take the following
parameters:

HTTP Functions

Your function is passed the ExpressJS parameters
(request,
response).
Use the response parameter to send a response.

Background Functions

Your function is passed the parameters
(data, context, callback).
See Background Functions
for more details on these parameters.

Node.js 6 (Deprecated)

In the Node.js 6 runtime, functions take the following parameters:

HTTP Functions

Your function is passed the ExpressJS parameters
(request,
response).
Use the response parameter to send a response.

Background Functions

Your function is passed the parameters
(event, callback).
See Background Functions
for more details on these parameters.

Python

In the Python runtime, functions take the following parameters:

HTTP Functions

Your function is passed a single parameter, (request),
which is a Flask Request
object. Return any value from your function that can be handled by the
Flask make_response
method. The result will be the HTTP response.

Background Functions

Your function is passed the parameters
(data, context).
See Background Functions
for more details on these parameters.

Triggers

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.

Note: Events are delivered at least once, which means that rarely,
spurious duplicates can occur.

Below is a table of the types of triggers supported and the flags used to
specify them during command-line deployment:

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.