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.
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.
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.
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.
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-event-filters-path-pattern=EVENTARC_EVENT_PATH_PATTERN] \ [--trigger-location=EVENTARC_TRIGGER_LOCATION] \ [--trigger-service-account=EVENTARC_TRIGGER_SERVICE_ACCOUNT] \ [--retry] \ ...
--gen2flag specifies that you are deploying to Cloud Functions (2nd gen). You must use Cloud Functions (2nd gen) to use Eventarc triggers.
--trigger-event-filtersflag 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_TYPEis required in order to specify the event type.
--trigger-event-filters-path-patternflag 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.
--trigger-locationflag 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.
--trigger-service-accountflag specifies a service account to use as the identity for the Eventarc trigger. See Trigger identity for more information.
--retryflag 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.
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.
- Click Add Eventarc trigger to add an event trigger. This opens the Eventarc trigger pane.
- In the Event provider field, select the product that provides the type of event you want to trigger your function.
- In the Event field, select an event type and complete any additional fields for your selected event type.
- In the Region field, select a location for the Eventarc trigger, if applicable. See Trigger location for more information.
- 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.
- 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.
- Click Save trigger.
- Learn how to write event-driven functions.
- Learn how to deploy a Cloud Function.
- See the following tutorials for examples of writing, deploying, and calling functions with an Eventarc trigger: