AWS lambda deployment of FastAPI gives the following error:
[ERROR] Runtime.ImportModuleError: Unable to import module 'users_crud': No module named 'pydantic_core._pydantic_core'
Traceback (most recent call last):
Though the pydantic lib is already installed. I am using version 3.10 which is now supported by AWS.
Lambda requires packages built for a specific architecture. Many packages have distributions for multiple architectures (see available distributions for pydantic-core
). By default, pip
installs the distribution suitable for the machine where you are running it on, which is not necessary the same architecture as your Lambda.
But you can force pip
to install packages for the architecture you want.
If your Lambda uses x86_64
, then you should select platform manylinux2014_x86_64
:
pip install pydantic-core --platform manylinux2014_x86_64 -t . --only-binary=:all:
-t .
- means install in the current directory.
However, the best way is to install all your dependencies with the required platform, rather than doing it for each package.
pip install -r requirements.txt --platform manylinux2014_x86_64 --target ./python --only-binary=:all:
Credits to this answer.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With