I'm trying to trigger a Firebase Cloud Function on a Realtime Database owned by a different app: the Hacker News API. I'm passing databaseUrl: https://hacker-news.firebaseio.com/ to admin.initializeApp(), and it deploys fine, but it never triggers, even though new items in this RTDB are regularly getting created.
const functions = require('firebase-functions')
const admin = require('firebase-admin')
admin.initializeApp({databaseUrl: 'https://hacker-news.firebaseio.com/'})
exports.itemUpdated = functions.database.ref('/v0/item/{id}').onCreate((snapshot, context) => {
functions.logger.log('Item: ', context.params.id, snapshot.val())
return null
})
I've tried it without databaseUrl in the local emulator, and it works fine. I've also tried a number of variations, eg functions.database.instance('hacker-news') and databaseUrl: 'https://hacker-news.firebaseio.com/v0', but no luck, it never triggers in production. Any idea what I'm missing?
It's just not possible to write functions in one project for a database in another project. The events generated from database changes always stay within the project.