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!

已提問 6 個月前檢視次數 2308 次
2 個答案
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
已回答 6 個月前
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.

已回答 2 個月前

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南