jstnchng jstnchng - 1 year ago 184
Node.js Question

Creating a lambda function in AWS from zip file

I am trying to create a simple lambda function, and I'm running into an error.

My code is basically

console.log('Loading function');

exports.handler = function(event, context) {
console.log('value1 =', event.key1);
console.log('value2 =', event.key2);
console.log('value3 =', event.key3);
context.succeed(event.key1); // Echo back the first key value
// context.fail('Something went wrong');

in a helloworld.js file. I zip that up and upload it as a zip file in the creating a lambda function section, and I keep getting this error:

"errorMessage": "Cannot find module 'index'",
"errorType": "Error",
"stackTrace": [
"Function.Module._resolveFilename (module.js:338:15)",
"Function.Module._load (module.js:280:25)",
"Module.require (module.js:364:17)",
"require (module.js:380:17)"

Anyone have any ideas?

Answer Source

The name of your file needs to match the module name in the Handler configuration. In this case, your Handler should be set to helloworld.handler, where helloworld is the file that would be require()'d and handler is the exported function. Then it should work with the same zip file.

AWS Lambda configuration screenshot

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download