从AWS Lambda在Cloud Firestore上执行写入操作

时间:2018-04-03 14:05:13

标签: amazon-web-services aws-lambda google-cloud-firestore alexa alexa-skills-kit

我一直在尝试将在AWS Lambda上运行的Alexa app技能连接到Cloud Firestore,因此我可以从Firestore DB执行一些读写操作。

我在堆栈溢出时遇到了其他问题并遵循了他们推荐的步骤,但每次执行该函数时都失败了。我做错了吗?

任何帮助或指向正确的方向都将是伟大的。

'use strict';
const Alexa = require('alexa-sdk');
const firebase = require('firebase-admin');
const APP_ID = '---';

const SKILL_NAME = '----';
const HELP_MESSAGE = '---';
const HELP_REPROMPT = '----';
const STOP_MESSAGE = '---';

module.exports.Test = (event, context, callback) => {

    context.callbackWaitsForEmptyEventLoop = false;

    if (firebase.apps.length == 0) {
        firebase.initializeApp({
            credential: firebase.credential.cert('---'),
            databaseURL: "---"
        });
    }

    var db = firebase.firestore();
    var docRef = db.collection('users')
        .doc('alovelace');

    var setAda = docRef.set({
        first: 'Ada',
        last: 'Lovelace',
        born: 1815
    });
};

const handlers = {
    'LaunchRequest': function () {
        this.emit('BasicFunction');
    },
    //Help
    'AMAZON.HelpIntent': function () {
        const speechOutput = HELP_MESSAGE;
        const reprompt = HELP_REPROMPT;

        this.response.speak(speechOutput)
            .listen(reprompt);
        this.emit(':responseReady');
    },
    //Cancel
    'AMAZON.CancelIntent': function () {
        this.response.speak(STOP_MESSAGE);
        this.emit(':responseReady');
    },
    //Stop
    'AMAZON.StopIntent': function () {
        this.response.speak(STOP_MESSAGE);
        this.emit(':responseReady');
    },
};

exports.handler = function (event, context, callback) {
    const alexa = Alexa.handler(event, context, callback);
    alexa.APP_ID = APP_ID;
    alexa.registerHandlers(handlers);
    alexa.execute();
};

AWS Lambda的错误日志

module initialization error: Error
at FirebaseAppError.Error (native)
at FirebaseAppError.FirebaseError [as constructor] (/var/task/node_modules/firebase-admin/lib/utils/error.js:39:28)
at FirebaseAppError.PrefixedFirebaseError [as constructor] (/var/task/node_modules/firebase-admin/lib/utils/error.js:85:28)
at new FirebaseAppError (/var/task/node_modules/firebase-admin/lib/utils/error.js:119:28)
at Function.Certificate.fromPath (/var/task/node_modules/firebase-admin/lib/auth/credential.js:142:19)
at new CertCredential (/var/task/node_modules/firebase-admin/lib/auth/credential.js:192:25)
at Object.cert (/var/task/node_modules/firebase-admin/lib/firebase-namespace.js:224:58)
at Object.<anonymous> (/var/task/index.js:14:41)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)

0 个答案:

没有答案