I am trying to add the OpenAI Python library to my AWS Lambda function. I tried to add them via AWS Lambda Layers as described in this guide. However, when executing my code, the addition of this line:
import openai
leads to this error-response:
Response
{
"errorMessage": "Unable to import module 'lambda_function': No module named 'pydantic_core._pydantic_core'",
"errorType": "Runtime.ImportModuleError",
"requestId": "c19b73e3-8c6d-4564-8be6-af7b03a79e00",
"stackTrace": []
}
Function Logs
START RequestId: c19b73e3-8c6d-4564-8be6-af7b03a79e00 Version: $LATEST
[ERROR] Runtime.ImportModuleError: Unable to import module 'lambda_function': No module named 'pydantic_core._pydantic_core'
Traceback (most recent call last):END RequestId: c19b73e3-8c6d-4564-8be6-af7b03a79e00
REPORT RequestId: c19b73e3-8c6d-4564-8be6-af7b03a79e00 Duration: 5.02 ms Billed Duration: 6 ms Memory Size: 128 MB Max Memory Used: 40 MB Init Duration: 166.39 ms
When following along the guide using the same package as them (requests), importing that package (requests) doesn't lead to an error.
Are there possible explanations for this behavior? I don't know where to start looking for fixes. Or are there any alternative methods of importing the library?