New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
No module named 'pydantic_core._pydantic_core' using AWS Lambdas #6557
Comments
I'm seeing this as well with
|
I asked about this on twitter and people said it was working fine for them - https://twitter.com/pydantic/status/1678298418983124992. |
Weird that pydantic is being installed from the sdist, not the wheel. If you don't have the rust toolchain available to build pydantic-core, and you're not installing a wheel, it makes sense that you can't import Maybe it's related to which architecture you're using? Could you give more information about how the lambda function is being |
It's also quite odd that fastapi (0.100.0)'s requirements are |
not really, they're trying to support as many versions of pydantic as possible - FastAPI 0.100 has support for both Pydantic V1 and Pydantic V2 - @tiangolo did an amazing job with this, so you can upgrade fastapi without having to upgrade pydantic yet. |
Forgot to mention the Lambda is running in arm64, the pydantic library was installed using a docker running the official python3.10 arm64 image. I'm calling the lambda function directly from the AWS console using a test event |
I'm on x86_64/amd64. My lambda isn't using pydantic directly if that helps. |
Can you show the log from building/installing python packages. |
Sure, I'm using CDK to build the lambda function
|
Well there's you're issue - you're installing the I've no what CDK is, but it/they most have instructions on how to "cross install" binary packages. Try asking on their GitHub. You might also try Googling how they cope with other binary packages like cryptography, pillow, bcrypt etc. |
Oh wow, that's right. Thanks for your help |
Yes, I'm definitely not using cross-built binaries, and it seems to be getting an appropriate binary for the AWS lambda
|
@johnbley it seems the pydantic-core wheel is specifically for python 3.7 (cp37), while you said you are running python 3.8 |
We do ship wheels for all python versions, possibly a mismatch between environment during build and runtime? |
Yep, that is it. I'll update the build environment to match versions. Thanks for your help! |
@quirozs I have the same issue. I use the official AWS lambda arm64 python 3.10 image to assemble the dependencies with platform set to arm64.
What did you do change from arm64 runtime to x86_64? I would like to stay on ARM though :-) |
@Esquive how are you building your lambda? You should be able to install the arm wheel instead of the x86_64 one. |
@davidhewitt I create my docker image:
And run the dependencies install:
The output from the container however displays the x86_64 versions of pydantic core has been pulled. |
According to the docker image registry your base image is an x86_64 (amd64) image: I'm not entirely sure how your image is working (emulation?) though I suspect that the python inside is identifying itself as x86_64, hence the wrong wheels getting pulled. It looks like Can you retry with
|
Hello @davidhewitt thanks for your answer, I just came here to tell you I figured it out to avoid you spending time on this. You are correct with the docker image. To really make sure:
On top of that I realised that docker was raising a warning on the architecture mismatch when not adding the platform option:
With the both above I was sure to be on an emulated arm64 environment and I pulled the correct pydantic packages. |
@davidhewitt I got this error with |
@25thbamofthetower can you share detail about how you are building your lambda? |
We have two generations of amplify apps. One app is pushed manually with The newer generation will build and deploy the app, including the lambda, automatically on commits to a specific git branch, e.g. main. Here is more information: https://docs.amplify.aws/cli/function/#function-templates This is the relevant section of it of the cloudformation template json:
|
@davidhewitt davidhewitt I use AWS CDK to build and deploy the lambda and api gateway
I don't think it's this, because switching back to As for the Python code, I'm using bare minimum fastapi (https://github.com/tiangolo/fastapi) and mangum (https://github.com/jordaneremieff/mangum). |
I had a similar issue and figured out that they old package was still included in the Lambda build... |
For anyone facing this issues with serverless and aws lambda. Following may help. This issue is due to different architectures. |
Just solved this error. For me the issue was occurring because I was using python 3.12 in AWS and in my layer. Once I switched both of them to 3.10 all worked just fine. |
Can you share what did you do? I checked the link, but couldnt find out. in importing openai, I faced with this error. really dont have any idea about it. |
I solved this using a Lambda Layer with all my deps, also in order to be sure about platforms and architecture I created it using a Cloud9 instance. |
For amplify you have no other option than this or running the build only in the pipeline with the right architecture (instead on your local environment)
|
I am writing a lambda function with openai as well and I have used a lambda layer where I pip installed openai on my local machine zipped the file and uploaded it as a layer it has pydantic core I still keep facing the same issue. I have chnaged the versions from 3.12 to 3.10 to even 3.8 but nothing seems to work at all. What do I do? |
@Vanshikashah318 , I would recommend to check your system's and lambda's architecture
|
I tried changing the architecture to arm64 also for both the lambda func as well as the layer but still the same issue. Any other suggestions what I could do I am also working on 3.12. |
In order to install pydantic-core I executed the AWS Documentation recommended command However, I had to add an additional platform name: 'manylinux_2_17_x86_64'. 'pydantic-core' appears to have a non-standard / misleading naming structure for uploading files. While the files are suffixed with 'manylinux2014_x86_64', the pip installer did not register it as the 'platform' name. It needed 'manylinux_2_17_x86_64' as the platform name. This installed it in a version that was compatiable with my x86_64, python version 3.9 Lambda. |
Your setting doesn't have anything regards architecture :| this issue is related to architecture mismatch problem |
I believe I use arm64 version but still got error on my lambda :( |
I guess it was something to do with cache (even though I cleaned it up) For whom had similar issue, I was able to build and deploy successfully from scratch. And I had to add layer manually (i dont know why) in aws console. Here is my serverless.yml
|
Hi All, I am using the following CDK code and facing the same issue, except with Python 3.12
The layer bundles some custom code and pydantic but I am receiving the following error whilst importing pydantic using the layer: I am using CDK pipelines, and I can see CodeBuild is using Image |
for anyone using windows I was able to solve this with the following command in powershell |
You rock, this worked for me. Python 3.12 runtime on Lambda, architecture x86_64. I only had to reinstall this one dependency too, everything else worked fine with "defaults". |
@peterrauscher Was that as part of an openai API deployment? |
Nope, FastAPI + motor + Beanie Good luck resolving your issue! |
Finally got it working with Amplify.
...on a linux box, zipping the content as per https://docs.aws.amazon.com/lambda/latest/dg/python-package.html#python-package-native-libraries and uploading it to AWS via the lambda layer console. |
Use this configuration if you're using MacOS and Serverless Framework Reference: AWS Lambda Docs custom:
pythonRequirements:
useStaticCache: false
useDownloadCache: false
pipCmdExtraArgs:
- "--platform manylinux2014_x86_64"
- "--implementation cp"
- "--python-version 3.11"
- "--only-binary=:all:"
- "--upgrade" The big issue is that if you don't set |
Facing the issue even though I'm using arm locally on my mac and configure as such on Lambda |
To debug this issue: try checking the contents of the Run the following code checks on startup of your lambda, before the import fails:
If these two checks do not match, your build steps have not installed the correct native code for your lambda's target platform. You should adjust your build steps to change the version of the installed library which gets installed. Most likely errors:
|
Thanks @davidhewitt. This helped us troubleshoot our issue! |
I had the same error in the AWS Lambda. |
This actually helped Thank you |
plus
this is what worked for me on Mac M1 |
Posting here in case anyone has any suggestions for AWS Glue 4.0 |
Oh yeah! You nailed it! Thank you so much! it works for openai now!!! |
I am still facing the error when dealing with Lambda. Upgrading nd downgrading runtime did not help. Any other suggestions? |
Initial Checks
main
branch, or equivalentDescription
I have pydantic 2.0.2 installed into my AWS Lambda with python3.10 and whenever I try to import pydantic I get the following exception:
I already checked that the module exists and it is accessible from python path. It was working with pydantic v1.
Example Code
No response
Python, Pydantic & OS Version
Selected Assignee: @davidhewitt
The text was updated successfully, but these errors were encountered: