Eventarc triggers

An Eventarc trigger enables a function to be triggered by any event type supported by Eventarc. When you specify an Eventarc trigger for a function, you provide event filters. Your function will be called whenever an event occurs matching the filters.

Event-driven functions in Cloud Run functions use Eventarc triggers. For more information, see Eventarc triggers in the Eventarc documentation. For a list of supported event types, see Event types supported by Eventarc.

For a function to use an Eventarc trigger, it must be implemented as a CloudEvent function. The event data is passed to your function in the CloudEvents format, with a CloudEvent data payload corresponding to the event type. The Google Events repository contains additional resources for working with event data.

Trigger location

Eventarc triggers are linked to certain locations. In general, the location of an Eventarc trigger should match the location of the Google Cloud resource that you want to monitor for events. In most scenarios, you should also deploy your Cloud Run function in the same region. See Understand Eventarc locations for more details about Eventarc trigger locations.

Trigger identity

Eventarc triggers are linked to service accounts to use as an identity when invoking your function. Your Eventarc trigger's service account must have permission to invoke your function. You may need to verify that the Default compute service account has the correct permissions to invoke your function.

Deployment

You can specify an Eventarc trigger when you deploy a function. See Deploy a Cloud Run function for general instructions on how to deploy a function. This section describes how to configure an Eventarc trigger that calls a function when an event that matches the filters occur during deployment.

gcloud

If you are deploying using the gcloud CLI, the flags shown are used to configure Eventarc triggers:

gcloud functions deploy YOUR_FUNCTION_NAME \
  --gen2 \
  --trigger-event-filters="type=EVENTARC_FILTER_TYPE" \
  [--trigger-event-filters=EVENTARC_EVENT_FILTER] \
  [--trigger-event-filters-path-pattern=EVENTARC_EVENT_PATH_PATTERN] \
  [--trigger-location=EVENTARC_TRIGGER_LOCATION] \
  [--trigger-service-account=EVENTARC_TRIGGER_SERVICE_ACCOUNT] \
  [--retry] \
...
  • The --gen2 flag specifies that you are deploying to Cloud Run functions. You must use Cloud Run functions to use Eventarc triggers.
  • The --trigger-event-filters flag specifies the event filters that the trigger will monitor. An event that matches all the filters will trigger calls to your function.

    • Required: Each trigger must have a supported event type in the form --event-filters="type=EVENTARC_FILTER_TYPE". This event type can't be changed after creation. To change EVENT_FILTER_TYPE, create a new trigger and delete the old one.
    • Optional: You can repeat the --trigger-event-filters flag with a supported filter in the form ATTRIBUTE=VALUE to add more filters.
  • The --trigger-event-filters-path-pattern flag specifies the event filters that the trigger will monitor in path pattern format. The filter must be in the form ATTRIBUTE=VALUE. See Understand path patterns for more information.

  • The --trigger-location flag specifies a location for the Eventarc trigger. See Trigger location for more information. If not specified, your function's region is used as the trigger location.

  • The --trigger-service-account flag specifies a service account to use as the identity for the Eventarc trigger. See Trigger identity for more information.

  • The --retry flag controls whether failed function calls are automatically retried. See Retrying event-driven functions for more information.

If you are creating a trigger for a direct Pub/Sub or Cloud Storage event, refer to the gcloud CLI instructions to configure a Pub/Sub and Cloud Storage trigger, respectively.

The Eventarc documentation contains examples of specifying event filters for different types of events. For more information, follow the instructions when creating a trigger for a specific provider, event type, and destination.

Console

If you are deploying using the Google Cloud console, you must select 2nd gen as your environment. Then you can configure an Eventarc trigger in the Trigger section.

  1. To add an event trigger, click Add trigger. This displays the following options:

    • Pub/Sub trigger
    • Cloud Storage trigger
    • Firestore trigger
    • Other trigger

    When you choose one of these options, the Eventarc trigger pane opens, where you can specify the details for the trigger.

    If you are creating a trigger for a direct Pub/Sub or Cloud Storage event, refer to the Google Cloud console instructions to configure a Pub/Sub and Cloud Storage trigger, respectively.

  2. If you pick Other trigger, use the Trigger type field in the Eventarc trigger pane to specify one of Google Sources, Custom, or Third-party.

    • Google Sources lets you specify triggers for Pub/Sub, Cloud Storage, Firestore, and other Google event providers. In the Eventarc trigger pane, use the Event provider field to select the product that provides the type of event you want to trigger your function. Then in the Event field, select the event you want to use as a trigger.

    • The Custom option lets you produce and consume events from your application code. Follow the prompts in the Eventarc trigger pane to create a channel. A channel is a resource that is used as a pipeline to deliver custom events from producers to consumers. Custom events are published to a channel and an Eventarc trigger subscribes to those events.

    • The Third-party option let you integrate with non-Google providers that offer an Eventarc source. See third-party events in Eventarc for details.

  3. In the Region field, select a location for the Eventarc trigger, if applicable. See Trigger location for more information.

  4. Optionally, in the Service account field, select a service account to be used as the identity of the Eventarc trigger. See Trigger identity for more information.

  5. Select or clear the Retry on failure checkbox to control whether failed function calls are automatically retried. See Retrying event-driven functions for more information.

  6. Click Save trigger.

Next steps