0

Added the following lines in the index.js file,

var config = {
host: 'http://localhost:9200'
}
var appmetrics = require('appmetrics-elk').monitor(config);

When trying to test the lambda function it says module initialization error, please find the stack trace for the error

 {
 "errorMessage": "/var/task/node_modules/appmetrics-elk/node_modules/appmetrics/appmetrics.node: invalid ELF header",
 "errorType": "Error",
 "stackTrace": [
 "Object.Module._extensions..node (module.js:434:18)",
 "Module.load (module.js:343:32)",
 "Function.Module._load (module.js:300:12)",
 "Module.require (module.js:353:17)",
 "require (internal/module.js:12:17)",
 "Object. (/var/task/node_modules/appmetrics-elk/node_modules/appmetrics/index.js:27:13)",
 "Module._compile (module.js:409:26)",
 "Object.Module._extensions..js (module.js:416:10)",
 "Module.load (module.js:343:32)"
 ]}

Using the latest appmetrics-elk version. Any help is appreciated. Thanks.

divya
  • 1
  • 1

1 Answers1

1

You don't give any information about what kind of environment you're attempting to run this in, so this is a bit of a stab in the dark:

According to ELF Header or installation issue with bcrypt in Docker container (2nd answer), this can happen when you've built your application locally and then attempt to get it to run in a container or cloud environment like Bluemix or Docker without clearing out your node_modules directory.

appmetrics-elk has a dependency on appmetrics which has native C code in it. When you npm i appmetrics-elk you will end up with a node_modules/appmetrics-elk/node_modules/appmetrics/appmetrics.node that is specific to your environment. If you then upload this to the cloud or to a container i.e a different environment, the binary appmetrics.node won't work there.

The solution is to just upload your application without a node_modules directory and include a dependency on appmetrics-elk in your package.json. The container should then build an appmetrics.node that works in that environment.

Community
  • 1
  • 1