I am working on a lambda that uses 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)
Code example:
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 a test) if third-party modules (other than aws-sdk) are not required. As soon as I just add a line, for example:
require('request') // or async, config and so on
Failed to complete the error described above. I tried calling these modules directly, specifying the full path with no luck. This is similar to finding the wrong directory when calling require .
Dropping process.env in the console gives:
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 I worked on the module - obviously, it worked at some point, but not for me.
Ideas? I feel like I am missing some kind of configuration unique to lambda here.