Error in OpenAI dependencies for Python Lambda Function

1

Hello, I'm creating a lambda function using the OpenAI API, and when testing it I get this error: { "errorMessage": "Unable to import module 'lambda_function': No module named 'pydantic_core._pydantic_core'", "errorType": "Runtime.ImportModuleError", "requestId": "6bddf918-25a1-4a6a-b523-d97db6ea94ed", "stackTrace": [] }

  • I've triple checked, Lambda Python environment is 3.11 and so is my local version (3.11.6)
  • I've moved all the dependency (site-packages) files into the root of the ZIP file
  • pydantic_core folder and in it _pydantic_core file exists in my ZIP.
  • This module is a sub dependency of OpenAI package
  • I tried packing the modules under 'python' sub directory in the ZIP file, and then it didn't even recognized 'openai' which makes me think it's something specific with 'pydantic_core'.

Any help will be very much appreciated. Thanks!

gefragt vor 6 Monaten2307 Aufrufe
2 Antworten
0

The following documentation demonstrate how it should packages should be included in the Lambda zip for Python: https://docs.aws.amazon.com/lambda/latest/dg/python-package.html#python-package-dependencies-layers:~:text=zip%20lambda_function.py-,Creating%20a%20Python%20layer%20for%20your%20dependencies,-The%20instructions%20in

I recommend using Lambda Layers for storing dependencies and then assign it to the Lambda function: https://docs.aws.amazon.com/lambda/latest/dg/packaging-layers.html#packaging-layers-paths

AWS
vtjean
beantwortet vor 6 Monaten
0

using openai==0.28.0 and install async-timeout==4.0.3 in the same folder. Be sure by creating the venv the version of your local-machine is same as the version of your Lambda python.

beantwortet vor 2 Monaten

Du bist nicht angemeldet. Anmelden um eine Antwort zu veröffentlichen.

Eine gute Antwort beantwortet die Frage klar, gibt konstruktives Feedback und fördert die berufliche Weiterentwicklung des Fragenstellers.

Richtlinien für die Beantwortung von Fragen