Function Triggers

Defining the trigger of your function.

A trigger is a statement that tells your function when and how to execute. A trigger is simply an announcement of what event should trigger your function to execute. When you connect a trigger with a Cloud Function, it will run when the triggering occurs.

There are two trigger types:

  • HTTP triggers

  • Event triggers

HTTP triggers

A function with an HTTP trigger is executed when an HTTP request is sent to the function's URL.

Event triggers

A function with an event trigger does not have a public URL. It executes in response to an event within your Cloud project. For example, a function might execute in response to changes to data in a database.

Cloud Functions supports the following event-based triggers:

When you are defining your function, it is important to tell what will trigger it. You can do this in the function.config.json file by giving the provider, event, and resource values.

function.config.json
{
    "name": "syncFirestoreCollectionWithBigQuery",
    "description": "Synchronize a Firestore collection into a BigQuery table.",
    "trigger": {
        "provider": "firestore",
        "event": "document.write",
        "resource": "collection/{docId}"
    },
    "tags": ["bigquery", "firestore"],
    "env": [
        {
            "name": "DATASET_NAME",
            "description": "The name of the dataset to store the documents",
            "required": true
        },
        {
            "name": "TABLE_NAME",
            "description": "The name of the table to store the documents",
            "required": true
        },
        {
            "name": "VIEW_NAME",
            "description": "The name of the view that represents the current state of the data",
            "required": true
        }
    ]
}

Supported trigger combinations.

Notice that the resource value is not necessary for all the providers.

Last updated