Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Firebase API in Lambda Functions AWS

Can someone please tell me how to do this?

This is what i have so far and It's not adding data into my database

I tested this out without using lambda functions on a regular web application and it works

var http = require('http');
var firebase = require('firebase');

exports.handler = (event, context, callback) => {

        var config = {
            apiKey: "AIzaSyCpk23423Iy_akmUniqUJhLt234324YPBE1vD7At8Laj4",
            authDomain: "echoproject-blah.firebaseapp.com",
            databaseURL: "https://echoproject-blah.firebaseio.com",
            storageBucket: "echoproject-blah.appspot.com",
            messagingSenderId: "83962234234322"
        };


   firebase.initializeApp(config);

   firebase.datetbase().ref('/employee/').push({
      med_number: Math.floor(Math.random() * 1000),
      full_name: 'John Smith',
      date_employed: Date.now(),
      email: '[email protected]',
      phone_number: '+123423423',
      profile_picture : 'blah.img'
   }).catch(function(err){
    console.log(err);
   });



    if (event.session.new) {
        onSessionStarted({ requestId: event.request.requestId }, event.session);
    }

    if (event.request.type === 'LaunchRequest') {
        onLaunch(event.request,
            event.session,
            (sessionAttributes, speechletResponse) => {
                callback(null, buildResponse(sessionAttributes, speechletResponse));
            });
    } else if (event.request.type === 'IntentRequest') {
        onIntent(event.request,
            event.session,
            (sessionAttributes, speechletResponse) => {
                callback(null, buildResponse(sessionAttributes, speechletResponse));
            });
    } else if (event.request.type === 'SessionEndedRequest') {
        onSessionEnded(event.request, event.session);
        callback();
    }
   } catch (err) {
    callback(err);
     }



}

I'm I missing something?

I'm trying to use firebase for my Amazon Echo. Would that be troubling it?

Is my firebase.database not getting recognize?

UPDATE

None of these solutions worked for me either

**SOLVED**

So after much frustration I decided to ditch the firebase Nodejs sdk and use the Firebase Endpoint urls

var myJSONObject = {
            med_number: Math.floor(Math.random() * 1000),
            full_name: 'John Bruh',
            date_employed: Date.now(),
            email: '[email protected]',
            phone_number: '+345345',
            profile_picture : '34534534'
        };
request({
    url: "https://echoproject-c78fghfgh6f.firebaseio.com/rest/saving-data/users.json",
    method: "POST",
    json: true,   // <--Very important!!!
    body: myJSONObject
}, function (error, response, body){
    if(error) console.log(error);
    console.log(response);
});
like image 954
Victor Le Avatar asked Nov 09 '22 08:11

Victor Le


1 Answers

Having database and not 'datetbase' might help:

firebase.datetbase().ref('/employee/').push({
like image 98
RationalDev likes GoFundMonica Avatar answered Nov 14 '22 23:11

RationalDev likes GoFundMonica