Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when using lambda destination: Cannot read properties of undefined (reading 'pathname') #2489

Closed
trietlam opened this issue Aug 19, 2024 · 2 comments · Fixed by #2498
Closed
Assignees

Comments

@trietlam
Copy link

trietlam commented Aug 19, 2024

Description

We use the serverless-newrelic-lambda-layers plugin for our lambdas, which pulls the latest newrelic layer. We have experienced an issue whereby the newrelic agent mistakenly identifies the event as an api gateway proxy event when the destination lambda is invoked, then tries to retrieve pathname property from a non-existent request url. This is preventing the lambda from running.

Expected Behavior

The lambda should be executed successfully

Troubleshooting or NR Diag results

this is the error log

{
    "errorType": "TypeError",
    "errorMessage": "Cannot read properties of undefined (reading 'pathname')",
    "stack": [
        "TypeError: Cannot read properties of undefined (reading 'pathname')",
        "    at Object.scrub (/opt/nodejs/node_modules/newrelic/lib/util/urltils.js:94:27)",
        "    at setWebRequest (/opt/nodejs/node_modules/newrelic/lib/serverless/aws-lambda.js:328:29)",
        "    at Runtime.wrappedHandler (/opt/nodejs/node_modules/newrelic/lib/serverless/aws-lambda.js:153:9)",
        "    at runInContextCb (/opt/nodejs/node_modules/newrelic/lib/shim/shim.js:1188:22)",
        "    at AsyncLocalStorage.run (node:async_hooks:338:14)",
        "    at AsyncLocalContextManager.runInContext (/opt/nodejs/node_modules/newrelic/lib/context-manager/async-local-context-manager.js:65:36)",
        "    at TransactionShim.applySegment (/opt/nodejs/node_modules/newrelic/lib/shim/shim.js:1178:25)",
        "    at Runtime.transactionWrapper (/opt/nodejs/node_modules/newrelic/lib/shim/transaction-shim.js:414:17)",
        "    at Runtime.patchHandlerSync [as handler] (/opt/nodejs/node_modules/newrelic-lambda-wrapper/index.js:140:25)",
        "    at Runtime.handleOnceNonStreaming (file:///var/runtime/index.mjs:1173:29)"
    ]
}

Steps to Reproduce

This can be replicated by using two lambdas.

One lambda deployed as a destination lambda.
The second lambda, performing any given operation, and configured to invoke the destination lambda on success or failure
After successfully executing the normal lambda operation the destination lambda will not be invoked and the logs will contain the information as per the description re: the undefined object when trying to get the pathname property.

This is the serverless.yml config snippet for reference

functions: 
 destination-lambda:
    handler: 'src/destination-lambda/index.handler'
    iamRoleStatements:
      - Effect: Allow
        Action:
          - 'lambda:InvokeFunction'
        Resource: 'arn:aws:lambda:${aws:region}:${aws:accountId}:function:${self:service}-${self:provider.stage}-main-lambda'

  main-lambda:
    handler: 'src/main-lambda/index.handler'
    destinations:
      onFailure: destination-lambda
      onSuccess: destination-lambda
    iamRoleStatements:
      - Effect: Allow
        Action:
          - 'lambda:InvokeFunction'
        Resource: 'arn:aws:lambda:${aws:region}:${aws:accountId}:function:${self:service}-${self:provider.stage}-destination-lambda'

Your Environment

  • Node version: 18

Additional context

I believe it has same root cause as #2291, where the logic to determine if the event is a proxy event only check for version property.
This is problematic because other events can also have "version": "1.0" or "version": "2.0". In this case, the lambda destination invocation event has "version": "1.0"

@workato-integration
Copy link

@newrelic-node-agent-team newrelic-node-agent-team moved this to Triage Needed: Unprioritized Features in Node.js Engineering Board Aug 19, 2024
@jsumners-nr jsumners-nr self-assigned this Aug 19, 2024
@github-project-automation github-project-automation bot moved this from In progress: Issues being worked on to Done: Issues recently completed in Node.js Engineering Board Aug 21, 2024
@bizob2828
Copy link
Member

@trietlam please upgrade to 12.3.0, this should fix your issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
3 participants