Function Store
  • Home
  • Getting started
    • Introduction
    • Installing a function
    • Reconfiguring a function
    • Uninstalling a function
    • FAQs
  • Reference
    • Requirements
      • Assign Roles
        • User permissions
      • Link a Billing account to your project
      • Enable the APIs
    • Projects
      • How to add a project
      • How to set up a project
    • Functions
      • Benefits
      • Use cases
      • Authentication when installing
      • Runtime configuration
      • Deploying with a ZIP file
    • Policies
      • How to add a Policy
      • How to remove a Policy
    • Authentication
      • Users
      • Roles
      • Permissions
    • Secrets
      • Creating a Secret
      • Using a Secret
      • Changing the value for a Secret
      • Deactivating a Secret
  • developers
    • Overview
    • Getting Started
    • Set up
    • Workspaces
      • Create a workspace
      • Workspace boilerplate
      • Node engines
    • Writing Functions
      • Function Anatomy
      • Configuration file
      • Function Triggers
      • Environment Variables
        • Type "text"
        • Type "number"
        • Type "email"
        • Type "url"
        • Type "json"
        • Type "boolean"
        • Type "select"
        • Type "multiselect"
        • Type "firestoreDocumentPath"
        • Type "firestoreCollectionPath"
        • Type "color"
      • Documentation
    • Push/Update your functions in the cloud
    • Continuous Integration
    • Publish functions in the Marketplace
    • Emulators
      • Initialize emulators in your workspace
      • Environment variables
      • Starting emulators
      • Testing your functions in the emulator
      • Importing existing data into local emulators
        • Exporting data from Cloud Firestore to local emulator
        • Exporting user accounts from Firebase to local emulator
    • Visual Studio Code Extension
      • Installing the extension
      • Extension UI
      • Functions list
      • Creating and editing functions
      • Emulators
      • Extension settings
      • Troubleshooting
        • "Command not found" error when executing a command
  • Billing
    • Understanding Billing
  • Security
    • Security
  • Resources
    • Events and Triggers
    • Best Practices
      • How to log events in functions?
    • Document your Functions
    • Editorial guidelines
    • Our Processes
      • Use Cases Analysis
  • Use cases
    • Custom Stripe Checkout
Powered by GitBook
On this page
  • HTTP triggers
  • Event triggers
  • Supported trigger combinations.

Was this helpful?

  1. developers
  2. Writing Functions

Function Triggers

Defining the trigger of your function.

PreviousConfiguration fileNextEnvironment Variables

Last updated 3 years ago

Was this helpful?

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.

provider
event
resource
topic

auth

user.create

-

-

auth

user.delete

-

-

firestore

document.create

e.g., /users/{uid}

-

firestore

document.write

e.g., /users/{uid}

-

firestore

document.update

e.g., /users/{uid}

-

firestore

document.delete

e.g., /users/{uid}

-

pubsub

event.publish

-

e.g., USER_CREATED

https

call

-

-

https

request

-

-

storage

object.archive

'bucket_1'

-

storage

object.delete

'bucket_1'

-

storage

object.finalize

'bucket_1'

-

storage

object.metadataUpdate

'bucket_1'

-

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

Cloud Pub/Sub Triggers
Cloud Storage Triggers
Direct Triggers
Cloud Firestore
Analytics for Firebase
Firebase Realtime Database
Firebase Authentication