I am trying to setup a Google Cloud Function with a Firebase Realtime Database Trigger and cannot make the function to be triggered when I add a document to the database.
What I want to happen is that when there is a new entry to the Firebase database collection yyy under project xxx I want the Cloud Function funtion-1 to be triggered. Function-1 is the default (as per below) and a test worked fine.
I am using the main console and created a function named function-1. I can see the function itself in the firebase console:
https://console.firebase.google.com/u/0/project/xxx/functions/list
The collection I set is under project xxx, named yyy, and I can access it under
https://console.firebase.google.com/u/0/project/xxx/database/firestore/data~2Fyyy
I am in the functions console:
https://console.cloud.google.com/functions/edit/us-central1/function-1?project=xxx
and the setup is as follows:
- Trigger: Firebase Realtime Database (Beta)
- Event Type: Create
- Database: xxx
- Path: /data/yyy
Runtime is Python 3.7
Code is default Google Cloud Functions code:
def hello_rtdb(event, context):
"""Triggered by a change to a Firebase RTDB reference.
Args:
event (dict): Event payload.
context (google.cloud.functions.Context): Metadata for the event.
"""
resource_string = context.resource
# print out the resource string that triggered the function
print(f"Function triggered by change to: {resource_string}.")
# now print out the entire event object
print(str(event))
requirements.txt is empty
I have used other triggers (HTTP, or PubSub) successfully in other Google Cloud Functions but I cannot get the function to be triggered by a database event. I have tried a wide range of options for the path variable but couldn't make it work.
The options I tried for the path variable are:
- /xxx/database/firestore/data/yyy
- /database/firestore/data/yyy
- /data/yyy
- /yyy
- yyy etc...
I am sure I am making a basic mistake but sadly the documentation isn't helping (probably because this is such a basic thing). How can I set this up in the right way?