5

I see in the GCP console that I can now create EventArc triggers on Firestore document creation using the method google.firestore.v1.Firestore.CreateDocument but how do I filter to only documents of a specific collection?

I assume I need to provide a 'Resource name' but I'm unclear what this should be and can't find any documentation about it. Anyone have any ideas?

My project name is ocapp and the collection I'm wanting triggers for is account.

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
owlbear
  • 103
  • 6

1 Answers1

1

To trigger on Firestore events, you can use the Audit Log type and filter for Firestore.

Supported methods for Firestore Audit Logs can be found in https://github.com/googleapis/google-cloudevents/blob/main/AUDIT_CATALOG.md#cloud-firestore

gcloud eventarc triggers create firestore-trigger \
   --destination-run-service=helloworld-firestore \
   --destination-run-region=us-central1 \
   --event-filters="type=google.cloud.audit.log.v1.written" \
   --event-filters="serviceName=firestore.googleapis.com" \
   --event-filters="methodName=google.firestore.v1.Firestore.Write" \
   --service-account=sample-service-account@PROJECT_ID.iam.gserviceaccount.com

The following tutorials show how to configure an Eventarc trigger for an Audit Log and consume the audit log event:

Grayside
  • 4,144
  • 21
  • 25
  • I tried this, but it will listen to everything, not just a specific collection. – Dale Nguyen Dec 02 '22 at 11:28
  • 1
    Eventarc just launched direct support for Firestore that supports watching a specific database and path. See https://cloud.google.com/firestore/docs/eventarc – asaad Apr 18 '23 at 01:35