AR98
AR98

Reputation: 11

Unable to import pydantic in lambda function

I am trying to import pydantic to a lambda via a lambda layer

and I keep getting this error

[ERROR] Runtime.ImportModuleError: Unable to import module 'main': No module named 'pydantic' Traceback (most recent call last):

The lambda uses python 3.9,Architecture x86_64, I have tried these commands separately :

and then compress the packages zip -r layer.zip layer/python and upload the layer and import it in the lambda

and I keep getting this error

[ERROR] Runtime.ImportModuleError: Unable to import module 'main': No module named 'pydantic' Traceback (most recent call last):

Upvotes: 0

Views: 522

Answers (1)

AR98
AR98

Reputation: 11

The following fixed the issue

  1. using pip install -r requirements.txt --python-version 3.9 --platform manylinux2014_x86_64 --target layer/python --only-binary=:all:
  2. make sure that the lambda python version is 3.9
  3. when creating the zip file it should be python/pydantic so it can be imported from the layer correctly

Upvotes: 1

Related Questions