New to AWS Layer, trying to use Layer as dependency for my Lambda function. However knock on this issue "errorType": "Runtime.ImportModuleError", could anyone point out my mistake?
Below's what I did:
Zipped and uploaded my Firebase-Admin dependency to Lambda via CLI. In the zip it contains (node_modules, package-lock.json, pacakage.json)
On my Lambda function I have set to use the Layer with version specified via AWS GUI.
Code on my Lambda function
var admin = require('firebase-admin');
var serviceAccount = require("../maskedPath.json");
admin.initializeApp({
credential: admin.credential.cert(serviceAccount),
databaseURL: "https://maskedProject.firebaseio.com"
});
var registrationToken = 'maskedToken';
exports.handler = function(event, context, callback) {
var message = {
data: {
score: '850',
time: '2:45'
},
token: registrationToken
};
admin.messaging().send(message)
.then((response) => {
// Response is a message ID string.
console.log('Successfully sent message:', response);
})
.catch((error) => {
console.log('Error sending message:', error);
});
}
Execute function with an empty test case
{}Issue as below:
{
"errorType": "Runtime.ImportModuleError",
"errorMessage": "Error: Cannot find module 'firebase-admin'\nRequire stack:\n- /var/task/index.js\n- /var/runtime/UserFunction.js\n- /var/runtime/index.js",
"trace": [
"Runtime.ImportModuleError: Error: Cannot find module 'firebase-admin'",
"Require stack:",
"- /var/task/index.js",
"- /var/runtime/UserFunction.js",
"- /var/runtime/index.js",
" at _loadUserApp (/var/runtime/UserFunction.js:100:13)",
" at Object.module.exports.load (/var/runtime/UserFunction.js:140:17)",
" at Object.<anonymous> (/var/runtime/index.js:43:30)",
" at Module._compile (internal/modules/cjs/loader.js:955:30)",
" at Object.Module._extensions..js (internal/modules/cjs/loader.js:991:10)",
" at Module.load (internal/modules/cjs/loader.js:811:32)",
" at Function.Module._load (internal/modules/cjs/loader.js:723:14)",
" at Function.Module.runMain (internal/modules/cjs/loader.js:1043:10)",
" at internal/main/run_main_module.js:17:11"
]
}
I have also tried to configure the my lambda function to use the layer via CLI with the line of code below, result was "LastUpdateStatus": "Successful"
aws lambda update-function-configuration --function-name maskedData --layers arn:aws:lambda:maskedData:layer:maskedData:1