Closed alessandroprudencio closed 6 months ago
@alessandroprudencio While I'm not familiar with Adonis, I do notice that in the stack trace there's a reference to './newrelic-lambda-wrapper.js'
. Typically the NR layer-installed wrapper would be set as the handler in the AWS Lambda environment, and not with ./
as a prefix. Dependencies installed from the layer are installed to /opt/nodejs/node_modules/
and not in /var/task
where user code runs.
The AdonisJs is framework for node js https://docs.adonisjs.com/guides/introduction
I don't know why it's pulling ./newrelic-lambda-wrapper.js
with ./
as a prefix.
but remembering that I have a layer of node_modules, I don't know if it interferes with something...
what do I do now @mrickard ?
@alessandroprudencio I don't think the layer of node_modules is interfering with anything. What you'll likely need to do is find out where that /.
prefix is being defined. You could open a support ticket with NR GTS--they can help you verify your function's environment variables and configuration where it might impact agent setup.
In your function code, do you import dependencies with that ./
prefix? We recommend not specifying directory path that way, so that the agent can leverage the Lambda environment's NODE_PATH
for finding functions and dependencies.
I am facing this exact issue as well. I am trying to attach the serverless-newrelic-lambda-layers plugin to my serverless framework function but I am getting the below error.
ERROR Error: Cannot find module './newrelic-lambda-wrapper.js' Require stack: - /var/task/s_process.js - /var/runtime/UserFunction.js - /var/runtime/Runtime.js - /var/runtime/index.js at Function.Module._resolveFilename (internal/modules/cjs/loader.js:902:15) at Module._require.i.require (/var/task/serverless_sdk/index.js:9:73131) at require (internal/modules/cjs/helpers.js:101:18) at Object.<anonymous> (/var/task/s_process.js:25:23) at Module._compile (internal/modules/cjs/loader.js:1085:14) at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10) at Module.load (internal/modules/cjs/loader.js:950:32) at Function.Module._load (internal/modules/cjs/loader.js:790:12) at Module.require (internal/modules/cjs/loader.js:974:19) at require (internal/modules/cjs/helpers.js:101:18) { code: 'MODULE_NOT_FOUND', requireStack: [ '/var/task/s_process.js', '/var/runtime/UserFunction.js', '/var/runtime/Runtime.js', '/var/runtime/index.js' ] }
Trace Log:
serverless_sdk/index.js
9 */(function(){var i="Expected a function",o="__lodash_placeholder__",s=[["ary",128],["bind",1],["bi
^ Error Cannot find module './newrelic-lambda-wrapper.js' Require stack: - /var/task/s_process.js - /var/runtime/UserFunction.js - /var/runtime/Runtime.js - /var/runtime/index.js
s_process.js
25 const userHandler = require('./newrelic-lambda-wrapper.js');
I assume the problem arises because it is importing the module with the "./" when it shouldn't. I am not manually importing the plugin anywhere nor have I made any code changes to install this plugin. All changes have been sole to the serverless.yml file. Attaching my serverless.yml below for reference as well.
org: XXX
app: XXX
service: XXX
provider:
name: aws
runtime: nodejs16.x
timeout: 900
environment:
NODE_ENV: dev
plugins:
- serverless-offline
- serverless-plugin-typescript
- serverless-newrelic-lambda-layers
custom:
newRelic:
accountId: ${param:NEW_RELIC_ACCOUNT_ID}
apiKey: ${param:NEW_RELIC_API_KEY}
enableFunctionLogs: true
functions:
process:
handler: app/handler.process
layers:
- ${param:XXX}
events:
- http:
path: process
method: post
environment:
XXX: ${param:XXX}
Any solutions that I should be trying?
The issue will not be fixed.
Has anyone already configured serverless + aws lambda + AdonisJS, but I can’t get it to work, I get the error below:
Cannot find module './newrelic-lambda-wrapper.js'
I’m using serverless-newrelic-lambda-layers and my serverless.yaml
Error:
ERROR Invoke Error {"errorType":"Error","errorMessage":"Cannot find module './newrelic-lambda-wrapper.js'\nRequire stack:\n- /var/task/s_AdonisApp.js\n- /var/runtime/UserFunction.js\n- /var/runtime/Runtime.js\n- /var/runtime/index.js","code":"MODULE_NOT_FOUND","requireStack":["/var/task/s_AdonisApp.js","/var/runtime/UserFunction.js","/var/runtime/Runtime.js","/var/runtime/index.js"],"stack":["Error: Cannot find module './newrelic-lambda-wrapper.js'","Require stack:","- /var/task/s_AdonisApp.js","- /var/runtime/UserFunction.js","- /var/runtime/Runtime.js","- /var/runtime/index.js"," at Function.Module._resolveFilename (internal/modules/cjs/loader.js:902:15)"," at Module._require.i.require (/var/task/serverless_sdk/index.js:9:73131)"," at require (internal/modules/cjs/helpers.js:101:18)"," at Object.<anonymous> (/var/task/s_AdonisApp.js:25:23)"," at Module._compile (internal/modules/cjs/loader.js:1085:14)"," at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)"," at Module.load (internal/modules/cjs/loader.js:950:32)"," at Function.Module._load (internal/modules/cjs/loader.js:790:12)"," at Module.require (internal/modules/cjs/loader.js:974:19)"," at require (internal/modules/cjs/helpers.js:101:18)"]}
my package.json: