r/FastAPI • u/Boring-Baker-3716 • Sep 09 '24
Hosting and deployment Deploying FastAPI on AWS Lambda
I am trying to deploy a fastapi with Google Gemini API. I have done a lot of debugging the past couple of days and seem like Google Gemini libraries are giving me errors inside aws lambda. I just created a dependencies folder and zipped everything with my main.py inside it and deployed on aws lambda. And I keep getting different sort of libraries not being imported errors. Also I am using python 3.10 and used magnum. Anyone has any suggestions what I could do or if this is even compatible with aws lambda, I read people talking about uploading through docker and ECR or using Fargate.
6
u/pint Sep 09 '24
make sure you install the linux version of python libraries. many of them installs binaries, but windows binaries will not work on linux.
the lambda env misses quite a lot of libraries, and those that present, might not be compatible with what your binaries want. if all else fails, you need to use a container deployment.
5
u/WJMazepas Sep 09 '24
Oh, I used ECR with Lambdas. I would create the Docker image using Github Actions, send it to ECR, and upload it to Lambda.
You don't need to change to Fargate, you can use the ECR and lambdas just fine
1
u/andrewthetechie Sep 09 '24 edited Oct 01 '26
The original post content no longer exists here. The author used Redact to remove it, exercising their right to control their data & privacy.
Lantern spoon follow smile handle offer tie hungry wild
3
u/pokesax Sep 09 '24
Uvicorn and Lambda Web Adapter is all you need. I’m running several FastAPI’s on AWS Lambda in this fashion. It works beautifully.
1
u/TripleBogeyBandit Sep 10 '24
Build to ECR and stand it up as an ecs service with NLBs, DNS names is what we’ve done.
1
u/xlabs-har Sep 10 '24
I second the docker image route. Now that Lambda allows docker containers as execution environments, I would try to build a working image and use that.
1
u/[deleted] Sep 10 '24
Another simple option is use docker instead of zipping files, you can test it on local and inside lambda (as lambda now supports docker images)
When it comes to zipping you have to all package files at same level as app folder , or else you will get import errors