Unable to Import Custom Python Package in Lambda Function Using Serverless Framework (original) (raw)

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:

serverless.yml (simplified):
service: my-service
provider:
name: aws
runtime: python3.12
functions:
myFunction:
handler: handler.my_function
plugins:


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.