I am trying to use FireStore-admin in NodeJS in AWS Lambda using layers. For this, I have zipped the node_modules and serviceAccount.json file in the following hierarchy and uploaded it to the layer:
nodejs->
The code is as follows:
var admin = require('firebase-admin');
var serviceAccount = require('./serviceAccount.json');
admin.initializeApp({
credential: admin.credential.cert(serviceAccount)
});
But I receive the following error when I run this lambda function:
"errorType": "Runtime.ImportModuleError",
"errorMessage": "Error: Cannot find module './serviceAccount.json'
You can also find the image of the zip attached below:
How do I access the json file and/or correct the hierarchy to get this working?
I think this should work so long as your file where this code lies is in the same directory as serviceAccount.json
import * as serviceAccount from './serviceAccount.json'
var admin = require('firebase-admin');
admin.initializeApp({
credential: admin.credential.cert(serviceAccount)
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.