I am working on a lambda that makes use of modules (async, request, etc)
Unable to import module 'index': Error at Function.Module._resolveFilename (module.js:338:15) at Function.Module._load (module.js:280:25) at Module.require (module.js:364:17) at require (module.js:380:17) at Object.<anonymous> (/var/task/index.js:1:63) at Module._compile (module.js:456:26) at Object.Module._extensions..js (module.js:474:10) at Module.load (module.js:356:32) at Function.Module._load (module.js:312:12) at Module.require (module.js:364:17)
Sample code:
var AWS = require('aws-sdk'), util = require('util'), request = require('request'); exports.handler = function(event, context) { console.log('test'); context.done(); };
It works fine (prints test) as long as no 3rd party modules (besides aws-sdk) are required. As soon as I just add a line such as:
require('request') // or async, config and so on
It fails with the above error. I have tried calling these modules directly as well by specifying the full path with no luck. It's like its looking at the wrong directory when calling require
.
Dumping process.env
in the console yields:
PATH: '/usr/local/bin:/usr/bin:/bin', LAMBDA_TASK_ROOT: '/var/task', LAMBDA_RUNTIME_DIR: '/var/runtime', AWS_REGION: 'us-west-2', AWS_DEFAULT_REGION: 'us-west-2', AWS_LAMBDA_LOG_GROUP_NAME: '/aws/lambda/Thumbnailer', AWS_LAMBDA_LOG_STREAM_NAME: '2015/12/10/[$LATEST]3f8ef236195448c88f206634bde6301b', AWS_LAMBDA_FUNCTION_NAME: 'Thumbnailer', AWS_LAMBDA_FUNCTION_MEMORY_SIZE: '512', AWS_LAMBDA_FUNCTION_VERSION: '$LATEST', NODE_PATH: '/var/runtime:/var/task:/var/runtime/node_modules',
Here's the module I was working off - evidently this used to work at some point but does not for me.
Ideas? I feel that I am missing some configuration unique to lambdas here.