An Eventarc trigger declares your interest in a certain event or set of events. You can configure event routing by specifying filters for the trigger, including the event source, and the target Cloud Run service.
Eventarc delivers events to the event receiver in a CloudEvents format through an HTTP request.
These instructions show you how to configure event routing to your Cloud Run service that is triggered by a direct Firebase Alerts event. For more details, see the list of supported direct events.
Prepare to create a trigger
Before you create a trigger, complete these prerequisites:
Console
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
Enable the Cloud Logging, Eventarc, and Eventarc Publishing APIs.
If applicable, enable the API related to the direct events. For example, for Firebase Alerts events, enable the Firebase Alerts API.
If you don't already have one, create a user-managed service account, then grant it the roles and permissions necessary so that Eventarc can manage events for your target service.
In the Google Cloud console, go to the Create service account page.
Select your project.
In the Service account name field, enter a name. The Google Cloud console fills in the Service account ID field based on this name.
In the Service account description field, enter a description. For example,
Service account for event trigger
.Click Create and continue.
To provide appropriate access, in the Select a role list, select the required Identity and Access Management (IAM) roles to grant to your service account for authenticated or unauthenticated invocations. For more information, see Roles and permissions for Cloud Run targets.
For additional roles, click
Add another role and add each additional role.Click Continue.
To finish creating the account, click Done.
gcloud
In the Google Cloud console, activate Cloud Shell.
At the bottom of the Google Cloud console, a Cloud Shell session starts and displays a command-line prompt. Cloud Shell is a shell environment with the Google Cloud CLI already installed and with values already set for your current project. It can take a few seconds for the session to initialize.
Enable the Cloud Logging, Eventarc, and Eventarc Publishing APIs.
gcloud services enable logging.googleapis.com \ eventarc.googleapis.com \ eventarcpublishing.googleapis.com
If applicable, enable the API related to the direct events. For example, for Firebase Alerts events, enable
firestore.googleapis.com
.If you don't already have one, create a user-managed service account, then grant it the roles and permissions necessary so that Eventarc can manage events for your target service.
Create the service account:
gcloud iam service-accounts create SERVICE_ACCOUNT_NAME
Replace
SERVICE_ACCOUNT_NAME
with the name of the service account. It must be between 6 and 30 characters, and can contain lowercase alphanumeric characters and dashes. After you create a service account, you cannot change its name.Grant the required Identity and Access Management (IAM) roles or permissions for authenticated or unauthenticated invocations. For more information, see Roles and permissions for Cloud Run targets.
Create a trigger
You can create an Eventarc trigger using the Google Cloud CLI or through the Google Cloud console.
Console
- In the Google Cloud console, go to the Eventarc Triggers page.
- Click Create trigger.
- Type a Trigger name.
This is the ID of the trigger and it must start with a letter. It can contain up to 63 lowercase letters, numbers, or hyphens.
- For the Trigger type, select Google sources.
- In the Event provider list, select
Firebase Alerts.
Note that the event provider name used in the associated Google Cloud documentation might not have a prefix of Cloud or Google Cloud. For example, on the console, Memorystore for Redis is referred to as Google Cloud Memorystore for Redis.
- In the Event type list, from the Direct events, select an event type.
- To specify the encoding of the event payload, in the Event data
content type list, select application/json or
application/protobuf.
Note that an event payload formatted in JSON is larger than one formatted in Protobuf. This might impact reliability depending on your event destination and its limits on event size. For more information, see Known issues.
- In the Region list, select global (Global).
For more information, see Eventarc locations.
- In the Attribute 1 field, the alerttype
resource ID acts as an
event filter. Select an operator for this filter:
- Equal
- Path pattern
For more information, see Understand path patterns.
- In the Attribute value 1 field, enter one of the
following:
appDistribution.inAppFeedback
: event is sent when a tester submits in-app feedback for a given appappDistribution.newTesterIosDevice
: event is sent when a new iOS tester device is registered for a given appbilling.planAutomatedUpdate
: event is sent when the billing plan for a Firebase project is automatically updated; for example, when a plan is downgraded due to payment issuesbilling.planUpdate
: event is sent when the billing plan for a Firebase project is modified by a user; for example, when a billing account is attached to or detached from a projectcrashlytics.missingSymbolFile
: event is sent when Firebase Crashlytics determines that it doesn't have the appropriate debug symbols to symbolicate an incoming crash reportcrashlytics.newAnrIssue
: event is sent when an app experiences a new application not responding (ANR) error (not for any subsequent, identical events)crashlytics.newFatalIssue
: event is sent when an app experiences a new fatal crash (not for any subsequent, identical events)crashlytics.newNonfatalIssue
: event is sent when an app experiences a new non-fatal error (not for any subsequent, identical events)crashlytics.regression
: event is sent when an app experiences a crash for an issue marked as closed for a previous app versioncrashlytics.stabilityDigest
: event is sent when there is a notification of the top trending issues in Crashlyticscrashlytics.velocity
: event is sent when a single issue is responsible for causing a significant number of app sessions to crashperformance.threshold
: event is sent when the performance of a metric crosses the set threshold
- Optionally, you can filter events for a specific Firebase App ID. Click add Add filter and specify the appid.
- Select the Service account that will invoke your service
or workflow.
Or, you can create a new service account.
This specifies the Identity and Access Management (IAM) service account email associated with the trigger and to which you previously granted specific roles required by Eventarc.
- In the Event destination list, select Cloud Run.
- Select a service.
This is the name of the service that receives the events for the trigger. The service must be in the same project as the trigger and will receive events as HTTP POST requests sent to its root URL path (
/
), whenever the event is generated. - Optionally, you can specify the Service URL path to send
the incoming request to.
This is the relative path on the destination service to which the events for the trigger should be sent. For example:
/
,/route
,route
,route/subroute
. - Click Create.
After a trigger is created, the event source filters cannot be modified. Instead, create a new trigger and delete the old one. For more information, see Manage triggers.
gcloud
You can create a trigger by running a gcloud eventarc triggers create
command along with required and optional flags.
gcloud eventarc triggers create TRIGGER \ --location=global \ --destination-run-service=DESTINATION_RUN_SERVICE \ --destination-run-region=DESTINATION_RUN_REGION \ --event-filters="type=google.firebase.firebasealerts.alerts.v1.published" \ --event-filters="alerttype=ALERT_TYPE" \ --event-data-content-type="EVENT_DATA_CONTENT_TYPE" \ --service-account=SERVICE_ACCOUNT_NAME@PROJECT_ID.iam.gserviceaccount.com"
Replace the following:
TRIGGER
: the ID of the trigger or a fully qualified identifier.-
DESTINATION_RUN_SERVICE
: the name of the Cloud Run service that receives the events for the trigger. The service can be in any of the Cloud Run supported locations and does not need to be in the same location as the trigger. However, the service must be in the same project as the trigger and will receive events as HTTP POST requests sent to its root URL path (/
), whenever the event is generated. -
DESTINATION_RUN_REGION
: (optional) the region in which the destination Cloud Run service can be found. If not specified, it is assumed that the service is in the same region as the trigger.
ALERT_TYPE
: the type of Firebase alert and can be one of the following values:appDistribution.inAppFeedback
: event is sent when a tester submits in-app feedback for a given appappDistribution.newTesterIosDevice
: event is sent when a new iOS tester device is registered for a given appbilling.planAutomatedUpdate
: event is sent when the billing plan for a Firebase project is automatically updated; for example, when a plan is downgraded due to payment issuesbilling.planUpdate
: event is sent when the billing plan for a Firebase project is modified by a user; for example, when a billing account is attached to or detached from a projectcrashlytics.missingSymbolFile
: event is sent when Firebase Crashlytics determines that it doesn't have the appropriate debug symbols to symbolicate an incoming crash reportcrashlytics.newAnrIssue
: event is sent when an app experiences a new application not responding (ANR) error (not for any subsequent, identical events)crashlytics.newFatalIssue
: event is sent when an app experiences a new fatal crash (not for any subsequent, identical events)crashlytics.newNonfatalIssue
: event is sent when an app experiences a new non-fatal error (not for any subsequent, identical events)crashlytics.regression
: event is sent when an app experiences a crash for an issue marked as closed for a previous app versioncrashlytics.stabilityDigest
: event is sent when there is a notification of the top trending issues in Crashlyticscrashlytics.velocity
: event is sent when a single issue is responsible for causing a significant number of app sessions to crashperformance.threshold
: event is sent when the performance of a metric crosses the set threshold
ALERT_TYPE
must be one of the following:- Equal; for example,
--event-filters="alerttype=appDistribution.inAppFeedback"
- Path pattern; for example,
--event-filters-path-pattern="alerttype=appDistribution.*"
or--event-filters-path-pattern="alerttype=crashlytics.new*"
.For more information, see Understand path patterns.
-
EVENT_DATA_CONTENT_TYPE
: (optional) the encoding of the event payload. This can beapplication/json
orapplication/protobuf
. The default encoding isapplication/json
.Note that an event payload formatted in JSON is larger than one formatted in Protobuf. This might impact reliability depending on your event destination and its limits on event size. For more information, see Known issues.
SERVICE_ACCOUNT_NAME
: the name of your user-managed service account.PROJECT_ID
: your Google Cloud project ID.
Notes:
- The
--location
flag must beglobal
. For more information, see Eventarc locations.
These flags are required:
--event-filters="type=google.firebase.firebasealerts.alerts.v1.published"
--event-filters="alerttype=ALERT_TYPE"
or--event-filters-path-pattern="alerttype=ALERT_TYPE"
Optionally, you can filter events for a specific Firebase App ID by using the
--event-filters="appid=APP_ID"
flag and by specifying an exact match.
- After a trigger is created, the event filter type can't be changed. For a different event type, you must create a new trigger.
- The
--service-account
flag is used to specify the Identity and Access Management (IAM) service account email associated with the trigger. - Optionally, specify a relative path on the destination Cloud Run
service to which the events for the trigger should be sent by using the
--destination-run-path
flag.
Example:
gcloud eventarc triggers create helloworld-trigger \ --location=global \ --destination-run-service=helloworld-events \ --destination-run-region=us-central1 \ --event-filters="type=google.firebase.firebasealerts.alerts.v1.published" \ --event-filters="alerttype=crashlytics.velocity" \ --service-account=${SERVICE_ACCOUNT_NAME}@${PROJECT_ID}.iam.gserviceaccount.com
This command creates a trigger called helloworld-trigger
for
the event identified as google.firebase.firebasealerts.alerts.v1.published
,
and for a crashlytics.velocity
alert type.
Terraform
You can create a trigger for a Cloud Run destination using Terraform. For details, see Create a trigger using Terraform.
List a trigger
You can confirm the creation of a trigger by listing Eventarc triggers using the Google Cloud CLI or through the Google Cloud console.
Console
In the Google Cloud console, go to the Eventarc Triggers page.
This page lists your triggers in all locations, and includes details such as names, regions, event providers, destinations, and more.
To filter your triggers:
- Click Filter or the Filter triggers field.
- In the Properties list, select an option to filter the triggers by.
You can select a single property or use the logical operator OR
to add
more properties.
To sort your triggers, beside any supported column heading, click
Sort.gcloud
Run the following command to list your triggers:
gcloud eventarc triggers list --location=-
This command lists your triggers in all locations, and includes details such as names, types, destinations, and statuses.