Is AWS Lambda the Right Choice for My FastAPI App?

0
8
Asked By CuriousCoder82 On

I'm looking to host my Python FastAPI application in a cost-effective manner, ideally for free. As my app doesn't have constant traffic and can handle some startup delay, I've considered AWS Lambda since I'm out of the free tier options. However, writing a pure Python application for Lambda feels tough for me, and I find it easier to run and test locally as an API. I'm ready to start hosting but want to know if AWS Lambda is the best route to take. I've heard about the Mangum adapter and my Docker image size is below 10 GB. What should I keep in mind while going forward with this?

2 Answers

Answered By TechieTom On

When using AWS Lambda, it's important to understand the lifecycle of the service and how it handles parallel requests. For instance, even if two calls happen right after each other, they could be processed by different Lambda instances. This means that any persistent data, like sessions, should be stored in a centralized database such as DynamoDB. Also, remember that Lambda environments can be suspended between invocations, which might disrupt active database connections. Keep an eye on temporary storage fills and environment state as well!

Answered By DevDiva23 On

Consider looking into AWS Lambda Powertools instead of focusing just on FastAPI. Powertools is designed to work well with Lambda, while FastAPI is better suited for continuous runs on ECS Fargate. Here's a useful link to get started: [AWS Lambda Powertools](https://docs.powertools.aws.dev/lambda/python/latest/)

HelpfulHank42 -

Actually, you can definitely run FastAPI on AWS Lambda using the Mangum adapter. It's a good choice for handling the API requests. Check out this resource for guidance: https://mangum.fastapiexpert.com/adapter/.

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.