Search code examples
amazon-web-servicesamazon-s3aws-lambdaamazon-elasticsearch

AWS lambda error


I'm trying to create a lambda function which takes apache log files from s3 bucket parses them into JSON documents and adds them to ES, as recommended in the following link :

https://github.com/awslabs/amazon-elasticsearch-lambda-samples

but I'm constantly facing the following error :

{
    "errorMessage": "Cannot find module 'byline'",
    "errorType": "Error",
    "stackTrace": [
        "Object.<anonymous> (/var/task/index.js:19:18)",
        "Module._compile (module.js:409:26)",
        "Object.Module._extensions..js (module.js:416:10)",
        "Module.load (module.js:343:32)",
        "Function.Module._load (module.js:300:12)",
        "Module.require (module.js:353:17)”
    ]
}

Kindly, recommend a solution for this.


Solution

  • Apparently you aren't including the byline package required by the Lambda function. You have to run npm install locally and package up your source code and all dependencies into a zip file, and upload that to Lambda. Lambda will not run npm install for you and it expects all dependencies to be uploaded. This is documented here.