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. This section describes how to configure an Eventarc trigger that calls a function when an event that matches the filters occur during deployment.
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] \ ...
--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. 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-filtersflag with a supported filter in the form
ATTRIBUTE=VALUEto add more filters.
- Required: Each trigger must have a supported event type in the form
--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.
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.
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.
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 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.
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 clear 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: