firebase-admin-node: Firebase AdminSDK in AWS Lambda (module initialisation error: Error)

Describe your environment

  • Operating System version: AWS Lambda
  • Firebase SDK version: 5.11.0
  • Firebase Product: Firestore

Describe the problem

I have been trying to connect my lambda function with Firestore DB using Admin SDK but its throwing error “module initialisation error: Error”

Its clearly an issue with Firesbase admin sdk, as every-time I comment this component, the rest of the component works fine. Could you please let me know what is the issue?

Steps to reproduce:

What happened? How can we make the problem occur? This could be a description, log/console output, etc.

Relevant Code:

'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();
};

####Logs from CloudWatch

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)

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 19 (6 by maintainers)

Most upvoted comments

Docker works only when I use javascript, but if I use serverless framework with nodejs-typescript, then docker does not work for me. But the following works -

https://medium.com/mtlserverless/firestore-the-serverless-framework-the-easy-way-262e574581d0