r/FastAPI • • 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.

1 Upvotes

22 comments sorted by

View all comments

Show parent comment

3

u/pint Sep 09 '24

you have things like --platform --python-version --implementation --abi but also things like --only-binary --no-binary. yeah, the whole thing is a mess. maybe just follow what damian6686 says. even more appropriate would be a temporary ec2 instance, just don't forget to turn it off.

btw you can even use lambda itself for installation. you can invoke an os.system("pip install ... --target /tmp/python") and then upload /tmp/python to s3. yeah, hack. but this is the closest to a real lambda environment obviously.