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 个月前

您未登录。 登录 发布回答。

一个好的回答可以清楚地解答问题和提供建设性反馈,并能促进提问者的职业发展。

回答问题的准则