Hi everyone,
I’m trying to deploy an AWS Lambda function using the Serverless Framework and run a function that depends on my own Python package. However, I’m encountering the following error at runtime:
{
“errorMessage”: “Unable to import module ‘handler’: No module named ‘pydantic_core._pydantic_core’”,
“errorType”: “Runtime.ImportModuleError”
}
Context:
- I’m using Python 3.12.9
- The custom package is installed using
pip install .
(from a local path) - I am using the Serverless Framework with a basic
serverless.yml
setup - The handler imports some modules that depend on
pydantic
- The function works locally, but fails when deployed
serverless.yml (simplified):
service: my-service
provider:
name: aws
runtime: python3.12
functions:
myFunction:
handler: handler.my_function
plugins:
- serverless-python-requirements
custom:
pythonRequirements:
dockerizePip: true
zip: true
slim: true
Things I've Tried:
* Using `serverless-python-requirements` with `dockerizePip: true` to match the Lambda environment
* Verifying that the package installs correctly locally and `pydantic_core` exists in the `.venv`
* Cleaning `.serverless` and `.venv` directories and redeploying
* Adding `pydantic` explicitly to `requirements.txt`
### Questions ###:
* Has anyone encountered this specific import issue with `pydantic_core._pydantic_core`?
* Is there a special build step or packaging approach needed when using packages like `pydantic` (with native extensions) in Lambda?
Any help would be greatly appreciated!
Thanks in advance.