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->
- node_modules
- package.json
- package-lock.json
- serviceAccount.json (contains credentials to connect to FireStore collection)
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?

serviceAccount.jsonis in.relative to the layer file, but the layer could be extracted to a different path in the Lambda runtime. I have 0 knowledge on how JSrequireworks, just throwing ideas around. Maybe have a look at github.com/awsdocs/aws-lambda-developer-guide/tree/master/… - ivica