Stay organized with collections Save and categorize content based on your preferences.

Eventarc triggers

In Cloud Functions (2nd gen), 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.

All event-driven functions in Cloud Functions (2nd gen) 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 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. By default, the Default compute service account is used.

Deployment

You can specify an Eventarc trigger when you deploy a function. See Deploy a Cloud Function for general instructions on how to deploy a function, and see below for additional information specific to configuring Eventarc triggers during deployment.

gcloud

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

gcloud functions deploy YOUR_FUNCTION_NAME \
--gen2 \
--trigger-event-filters=EVENTARC_EVENT_FILTERS \
[--trigger-location=EVENTARC_TRIGGER_LOCATION] \
[--trigger-service-account=EVENTARC_TRIGGER_SERVICE_ACCOUNT] \
[--retry] \
...
  • The --gen2 flag specifies that you are deploying to Cloud Functions (2nd gen). You must use Cloud Functions (2nd gen) to use Eventarc triggers.
  • The --trigger-event-filters flag specifies the event filters that the trigger will monitor. Events matching the filters will trigger calls to your function. You can specify this flag multiple times to add multiple filters. Each filter must be in the form ATTRIBUTE=VALUE. At a minimum, the filter type=EVENT_TYPE is required in order to specify the event type.
  • 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.

The Eventarc documentation contains examples of specifying event filters for different types of events - see Create a trigger using gcloud.

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. Click Add Eventarc trigger to add an event trigger. This opens the Eventarc trigger pane.
  2. In the Event provider field, select the product that provides the type of event you want to trigger your function.
  3. In the Event field, select an event type and complete any additional fields for your selected event type.
  4. In the Region field, select a location for the Eventarc trigger, if applicable. See Trigger location for more information.
  5. 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.
  6. Select or deselect the Retry on failure checkbox to control whether failed function calls are automatically retried. See Retrying event-driven functions for more information.
  7. Click Save trigger.

Next steps