在Lambda函数AWS中使用Firebase API

时间:2016-09-22 05:38:31

标签: javascript node.js firebase firebase-realtime-database aws-lambda

有人可以告诉我怎么做吗?

这是我到目前为止所没有的数据

我在常规Web应用程序上使用lambda函数测试了它,并且它可以正常工作

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: '23432432@yahoo.com',
      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);
     }



}

我错过了什么?

我正在尝试将firebase用于我的Amazon Echo。这会让人不安吗?

我的firebase.database无法识别吗?

更新

这些solutions都不适用于我

** **解决

所以在经历了很多挫折之后,我决定抛弃firebases sdk并使用Firebase端点网址

var myJSONObject = {
            med_number: Math.floor(Math.random() * 1000),
            full_name: 'John Bruh',
            date_employed: Date.now(),
            email: 'vi43544tle@yahoo.com',
            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);
});

1 个答案:

答案 0 :(得分:1)

拥有数据库而不是'datetbase'可能有所帮助:

firebase.datetbase().ref('/employee/').push({