I'm trying to write to my Firebase database using a Twilio function (almost exactly the same as AWS Lambda function, if you're familiar with that), but I'm unable to do so. Firebase is generating a reference key for me, but nothing appears in my Firebase database when I check it. I don't see any error message from my function. Here's what I'm working with.
var firebase = require('firebase');
exports.handler = function(context, event, callback) {
var firebaseConfigs = {
apiKey: "[my_api_key]",
authDomain: "[my_domain].firebaseapp.com",
databaseURL: "https://[my_domain].firebaseio.com",
projectId: "[my_project_id]",
storageBucket: "[my_domain].appspot.com",
messagingSenderId: "[my_sender_id]"
};
if (!firebase.apps.length) {
firebase.initializeApp(firebaseConfigs);
console.log('Initialized Firebase app');
}
console.log('saving to firebase');
var ref = firebase.database().ref().push({
emailAddress: event.emailAddress,
test: 'test'
});
console.log('saved to ',ref.key)
setTimeout(function() {}, 3000);
callback();
};
In my function logs, I see the following:
- Execution Started
- Initialized Firebase app
- saving to firebase
- saved to [-LdVpr...]
- Execution ended in 974.16ms using 97 MB
Clearly Firebase is generating a key for me, but the key [-LdVpr...] is not added to my database. What could be happening, and how can I further troubleshoot this?