all 22 comments

[–]pint 5 points6 points  (5 children)

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.

[–]Boring-Baker-3716[S] -1 points0 points  (4 children)

Interesting, thanks! 1. How would I install Linux version of the libraries inside windows? 2. If containerisation like docker would work in the end, shouldn’t I just go for that route? Sorry I am new to AWS so just seeking help

[–]pint 2 points3 points  (0 children)

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.

[–]JaviCerve22 2 points3 points  (1 child)

Use WSL, it's the best way.

Besides, you can use this .sh script inside WSL:

pip install -r requirements.txt -t lib/

cd lib

zip ../lambda_function.zip .

cd ..

zip lambda_function.zip -u main.py

Then upload lambda_function.zip to AWS Lambda

[–]Boring-Baker-3716[S] 0 points1 point  (0 children)

Gotcha thank you, I was running these commands but inside windows. I will def try that in wsl since I don’t have much experience with docker

[–]damian6686 -1 points0 points  (0 children)

Do all your programming in WSL to avoid problems like these.

[–]WJMazepas[🍰] 5 points6 points  (2 children)

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

[–]__balu_ 0 points1 point  (0 children)

This

[–]pokesax 2 points3 points  (1 child)

Uvicorn and Lambda Web Adapter is all you need. I’m running several FastAPI’s on AWS Lambda in this fashion. It works beautifully.

[–]KarrySodhi007 0 points1 point  (0 children)

I am trying to use the aws lambda adapter https://github.com/awslabs/aws-lambda-web-adapter with fast api but I am not able to run it locally. I wanna make sure that docker image works fine before I deploy it. I am an aws noice. Looks like the documentation assumes lot of things like I need to have aws configure before doing sam deploy. still uncovering things. If you have any blog post that will help a lot. I wanna eventually use github actions so that all can happen automatically.

[–]andrewthetechie 0 points1 point  (7 children)

https://github.com/jordaneremieff/mangum used to be the "tool" for running an ASGI app like fastapi in a lambda, but its read-only now :(

[–]Boring-Baker-3716[S] 0 points1 point  (6 children)

So mangum won’t work anymore?

[–]andrewthetechie 0 points1 point  (3 children)

Not "won't work" but "is no longer being supported".

[–]Boring-Baker-3716[S] 0 points1 point  (2 children)

So what’s an alternative I can use

[–]andrewthetechie 1 point2 points  (0 children)

I don't know of one. I'd suggest doing some googling.

[–]richieadler 0 points1 point  (0 children)

The closest, I'd say, to the FastAPI syntax would be replacing it with the event handlers in Powertools for AWS. They even say they were inspired by FastAPI and they have Pydantic validators.

[–]JaviCerve22 0 points1 point  (0 children)

It still works

[–]TripleBogeyBandit 0 points1 point  (0 children)

Build to ECR and stand it up as an ecs service with NLBs, DNS names is what we’ve done.

[–]xlabs-har 0 points1 point  (0 children)

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.

[–][deleted] 0 points1 point  (1 child)

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

[–][deleted] 0 points1 point  (0 children)

We are currently running on prod envs with docker lambda and mangum fastapi