0

I have a lambda function(runtime: Nodejs 4.3) and I need to store data in elasticache. The engine is redis. This is my function:

const redis = require("redis");
exports.handler = function (event, context, callback) {
    callback(null, {});
};

Lambda returns "errorMessage": "Cannot find module 'redis'", error. Should I add nom redis package in zip?

hhs
  • 716
  • 1
  • 6
  • 22

1 Answers1

0

All npm modules needs to be installed in node_modules folder. You can use npm install --save package name command to install node_module and save its name in package.json. Refer this link for --save option explanation.

Zip the index.js and node_moule for upload. index.js file is your handler function, if your handler name is different, use that name for js file and zip file.

Note:- It is best to use node-lambda module for developing your code on local ec2 machine. Execute it with the node-lambda run and use node-lambda deploy for deploying the code over lambda. Zipping and all other things will be taken care by node-lambda.

Community
  • 1
  • 1
Anup Tilak
  • 336
  • 3
  • 15