serverless / dashboard

MIT License
24 stars 10 forks source link

ModuleNotFoundError: Unable to import module in Lambda with Serverless SDK #888

Open leonbeckert opened 4 months ago

leonbeckert commented 4 months ago

Description

We are encountering a ModuleNotFoundError during the execution of an AWS Lambda function configured through Serverless. The error suggests that the function's handler module cannot be located or is not recognized as a Python package. This issue arose upon redeploying the function without any changes to the path or configuration, which previously worked in past deployments.

Error Details

Serverless.yml

platformMainAgent:
    description: Handle various type of text requests
    role: platformMainAgentRole
    handler: platform/agents/mainAgent/lambda_function.handler
    architecture: arm64
    timeout: 60
    runtime: python3.9
  events:
      - schedule:
          rate: ${self:custom.rates.${self:provider.stage}}
          enabled: true
          inputTransformer:
            inputTemplate: '{}'
    layers:
      - { Ref: OpenaiLambdaLayer }
      - { Ref: TiktokenLambdaLayer }

Expected Behavior

The Lambda function should successfully locate and import the specified handler module without errors, as it did in previous deployments.

Actual Behavior

The function fails to start due to an inability to import the specified module, indicating a potential issue in how the Serverless SDK handles module paths or packages, especially since there were no changes made to the configuration or paths that previously worked.

Steps to Reproduce

Reproduction does not seem to be possible. Serverless support writes the following:

We have recently been seeing sporadic issues with AWS Lambda and importing of Lambda layers, and not specifically those created Serverless Dashboard. Unfortunately, the incidences have been very low volume (2-3 users affected so far we have encountered) and we have not been able to replicate ourselves.

Additional Information

This issue is particularly perplexing as it occurred without any modifications to the Lambda configuration or the file structure. It suggests a potential underlying issue with how the Serverless framework or AWS Lambda handles redeployments or updates to the runtime environment. Insights or recommendations on resolving this sudden error would be highly appreciated.

What we tried

-> nothing works