newrelic/serverless-newrelic-lambda-layers

Python layer version 41: Failed to import module [HANDLER]

osama-aref opened this issue · 5 comments

Hi,

I've been using serverless-newrelic-lambda-layers for a while in my AWS serverless lambda application. Previous versions of the Python layer were working fine, but with the current layer version (arn:aws:lambda:eu-west-1:451483290750:layer:NewRelicPython39:41) I'm getting this error: Runtime.ImportModuleError: Unable to import module 'newrelic_lambda_wrapper': Failed to import module 'src/api/credits/get': No module named 'src/api/credits/get' Traceback.
No code changes have been made, only change is that the latest layer is getting fetched.
Snippets from serverless.yml:

provider:
  name: aws
  runtime: python3.9
  timeout: 10
  memorySize: 128

package:
  # Exclude all files by default, then specify which files to include in each function.
  patterns:
    - '!./**'
  individually: true

custom:
  newRelic:
    accountId: [ACCOUNT ID]
    apiKey: [KEY]
    enableFunctionLogs: true
    nrRegion: 'eu'
    disableLicenseKeySecret: true

functions:
  getCreditsAPI:
    handler: src/api/credits/get.default
    events:
     - http:
         method: GET
         path: /credits
    package:
      patterns:
        - src/api/credits/get.py

Any help is appreciated.
Thanks!

Thank you for reporting this @osama-aref. We have reviewed this issue and it looks like we may have a bug in the lambda layers parsing logic for imported handlers. We will work on a fix for this and update you on our release timeline once we have a better sense of it.

@umaannamalai I am also experiencing this issue, do you know if there is a potential work around for this?

@ConorButte The only fix would be downgrading to a previous version of the layer that doesn't have this bug ( Layers released before Apr 12, 2023.) or not specifying a handler with a module path. Ex: something like this would work: "app.handler" but this would not: "foo/app.handler".

We have released a new version of each layer with the fix in place. Update to the latest available version.