Simple Serverless FastAPI with AWS Lambda

Ғылым және технология

Learn how to create a simple Serverless FastAPI with AWS Lambda and API Gateway. The Serverless FastAPI will be ran on an AWS Lambda by using Mangum and AWS API Gateway will handle routing all requests to the Lambda.
00:00 -- Intro: Serverless FastAPI with AWS Lambda
00:34 -- 1. Prerequisites
00:41 -- 2. Create FastAPI Application
03:07 -- 3. Configure Routing
07:50 -- 4. Convert to Lambda
08:34 -- 4. Package Lambda
09:53 -- 5. Create S3 Bucket
10:14 -- 6. Create Lambda Function
12:11 -- 7. Test Lambda Function
12:55 -- 8. Setup API Gateway
Check the blogpost for current updates:
www.deadbear.io/simple-server...
Repository for FastAPI Lambda:
github.com/deadbearcode/simpl...
FastAPI:
fastapi.tiangolo.com/
Mangum:
pypi.org/project/mangum/
Blog - www.deadbear.io
Twitter - / deadbearcode
Instagram - / deadbearcode

Пікірлер: 94

  • @sahilchhugh2974
    @sahilchhugh29743 жыл бұрын

    Happiness - Finding such quality content. Sadness - Last uploaded video was 3 months ago.

  • @deadbearcode

    @deadbearcode

    3 жыл бұрын

    Lol, sorry! I'm working on making more videos. I have been busy with work lately. But I'm working on it! Thanks for watching!

  • @BilalAhmed-nt9gi
    @BilalAhmed-nt9gi3 жыл бұрын

    I usually don't subscrib to youtube... and here just subscribed in first 20 - 30 seconds.

  • @deadbearcode

    @deadbearcode

    3 жыл бұрын

    🤯🤗

  • @RayTawil-en1ws
    @RayTawil-en1ws Жыл бұрын

    Fantastic video! You did a fantastic job making it followable quickly without too much details but while at the same time helping the viewer understand what each step is doing. I forward this video to every person I need to get ramped up on deploying FastAPI to Lambda!

  • @JoshPeak
    @JoshPeak2 жыл бұрын

    Hey this tutorial got me up and running using the new Lambda Function URLs so I could skip the API Gateway section. Love how I can test locally and same code deploys to the cloud. Legend!

  • @waqaskhalidobeidy2673
    @waqaskhalidobeidy26733 жыл бұрын

    This was a great walkthrough of FastAPI and AWS Lambda integration. Loved it. Congrats you have just earned a new subscriber!

  • @deadbearcode

    @deadbearcode

    3 жыл бұрын

    Glad you liked it! Thanks for subscribing!

  • @BilalAhmed-nt9gi
    @BilalAhmed-nt9gi3 жыл бұрын

    When this video started I was about to skip it I thought it's Ad. The Quality is just super super great (Y) Thanks man

  • @deadbearcode

    @deadbearcode

    3 жыл бұрын

    Man that's awesome! Thanks so much for the support!

  • @sanjeethflautist

    @sanjeethflautist

    3 жыл бұрын

    Completely agree... one making video would be good.. so that we can learn how to create good content

  • @deadbearcode

    @deadbearcode

    3 жыл бұрын

    I could be open to that 🤔 Maybe on a different channel.

  • @jackrorystaunton4557
    @jackrorystaunton45573 жыл бұрын

    awesome! very helpful info on that apirouter for keeping things organized/scalable

  • @pratikkotian1729
    @pratikkotian17293 жыл бұрын

    This is a really super fun and simple AWS Lambda with Python and FastAPI tutorial. Thanks Man :D

  • @deadbearcode

    @deadbearcode

    3 жыл бұрын

    Awesome glad you enjoyed it! Thanks for wstching :)

  • @kuntiechan
    @kuntiechan Жыл бұрын

    very detailed and easy to follow. thank you!

  • @jonmonts7412
    @jonmonts74123 жыл бұрын

    Great tutorial and video production quality. Hope to see more from you.

  • @deadbearcode

    @deadbearcode

    3 жыл бұрын

    Wow! Thanks so much!

  • @pmsoltani
    @pmsoltani3 жыл бұрын

    I've just created my AWS account and had absolutely no idea how to navigate the console. Your tutorial saved my day (or week). BTW... the video quality is 😎🚀

  • @deadbearcode

    @deadbearcode

    3 жыл бұрын

    So glad to hear! The console is definitely a little overwhelming at first lol. Thanks!

  • @draytond
    @draytond3 жыл бұрын

    Superb tutorial. Looking forward to more high quality videos. Cheers!

  • @deadbearcode

    @deadbearcode

    3 жыл бұрын

    Thanks! I’m Working on some more stuff!

  • @jugsma6676
    @jugsma66763 жыл бұрын

    I am waiting for another series when the application connects with the database from AWS lambda, hope to see that soon. And, btw this video is great, liked.

  • @deadbearcode

    @deadbearcode

    3 жыл бұрын

    Hey thanks for watching and the like! I have one like that in the works!

  • @shashwatrathod1342
    @shashwatrathod13423 жыл бұрын

    Thank you so much! Great video.

  • @deadbearcode

    @deadbearcode

    3 жыл бұрын

    Thanks for watching!

  • @ajaybharti6847
    @ajaybharti68472 жыл бұрын

    Loved your tutorial!

  • @deadbearcode

    @deadbearcode

    2 жыл бұрын

    🙌 Awesome!

  • @ramil17998
    @ramil179983 жыл бұрын

    That was a really good tutorial, thanks for that! Would be cool to see how the process of updating the api would look like (from some local change to redeploy). Good job!

  • @deadbearcode

    @deadbearcode

    3 жыл бұрын

    Heres a walkthrough of setting up a cicd pipeline for it! kzread.info/dash/bejne/k4iNyrGNcq6Ym6g.html

  • @ramil17998

    @ramil17998

    3 жыл бұрын

    @@deadbearcode reading my mind! That's a subscribe sir :)

  • @deadbearcode

    @deadbearcode

    3 жыл бұрын

    Awesome!

  • @bazzinga204
    @bazzinga2043 жыл бұрын

    This is absolutely brilliant! Subscribed for more :D

  • @deadbearcode

    @deadbearcode

    3 жыл бұрын

    Thanks!

  • @csvidzz
    @csvidzz3 жыл бұрын

    Quality content! Keep it up bro

  • @deadbearcode

    @deadbearcode

    3 жыл бұрын

    Thanks! Will do!

  • @WellLairyDrift
    @WellLairyDrift3 жыл бұрын

    Great tutorial! Got me up and running as a total AWS noob in a couple of hours. Well done!

  • @deadbearcode

    @deadbearcode

    3 жыл бұрын

    Thank you! AWS can be pretty overwhelming at times so i’m happy to hear it helped!

  • @nabillahssini
    @nabillahssini2 жыл бұрын

    Thank you so much, you are amazing !

  • @sarahasad8707
    @sarahasad87073 жыл бұрын

    Well described.

  • @Cal97g
    @Cal97g3 жыл бұрын

    Underrated content

  • @deadbearcode

    @deadbearcode

    3 жыл бұрын

    Thanks! i appreciate the watch!

  • @maximussnow
    @maximussnow3 жыл бұрын

    This is Great ! Do share some FastAPI tutorials

  • @deadbearcode

    @deadbearcode

    3 жыл бұрын

    Awesome glad you liked it! I’m planning on it!

  • @abhijeetbedagkar3143
    @abhijeetbedagkar31432 жыл бұрын

    What are the benefits / challenges of running another web framework inside lambda to handle routing vs when routing could be achieved through api gateway

  • @ThePirateHistory
    @ThePirateHistory3 жыл бұрын

    Despite that this is about Serverless, this is the best intodaction in fastapi that I have seen, everything is adequate, structuring, clearly, tell me where to read about such structurization? and it would not be necessary to make endpoints, folders for user, and there let's make the endpoints file and then collect everything in the endpoints file? Well, let's say user can have models, and so on!

  • @sharifahmed1925
    @sharifahmed19253 жыл бұрын

    Great tutorial! Thank you! Please can you create more tutorials for FastAPI :)

  • @deadbearcode

    @deadbearcode

    3 жыл бұрын

    Thank you! They are in the works!

  • @therocketmanprince682
    @therocketmanprince6823 жыл бұрын

    Nice video . upload more videos please

  • @deadbearcode

    @deadbearcode

    3 жыл бұрын

    Thanks! Working on more vids!

  • @gopietz
    @gopietz2 жыл бұрын

    Whats the advantage of using Lambda with FastAPI instead of defining endpoints in Python directly within Lambda?

  • @cristian-bull
    @cristian-bull3 жыл бұрын

    You saved my ass. Thank you sir

  • @deadbearcode

    @deadbearcode

    3 жыл бұрын

    Haha awesome!

  • @sntshkmr60
    @sntshkmr602 жыл бұрын

    Hi Sean, very nice tutorial. I have been looking up the internet on how to run my Flask/FastAPI application on Lambda lately and this tutorial clears many doubts. Until now, it's clear that I don't need multiple Lambdas to map to each endpoint of my API server. Still, I have couple doubts still in my mind related to Serverless/Lambda and FastAPI. I'll go ahead and ask it out. 1. Lambda responds to the endpoint it receives. Is the FastAPI server always running in the background? Or does it starts every time the function is invoked? 2. How does Lambda in this case handles global state? This question again is where Lambda always keeps running the FastAPI server or starts when invoked.

  • @user-hn1cy5ee5l

    @user-hn1cy5ee5l

    2 жыл бұрын

    It's just invoking a handler, lambda doesn't start uvicorn and mangum is needed to convert incoming "event" from lambda to something FastApi can understand

  • @snap-reviewsdotcom
    @snap-reviewsdotcom9 ай бұрын

    Great tutorial thanks. But what about the 30sec and 6MB data limit for a Lambda function? If you have long-running functions or need to return huge datasets, this won't work, right? To solve the 6MB limit you'd have to implement streaming using AWS Lambda Streaming (Lambda InvokeWithResponseStream API) using the Lambda Web Adapter. That would be a good tutorial!

  • @tech4028
    @tech40283 жыл бұрын

    Thank you! Really nice that you're using tools like FastAPI. I'd like to see how to deploy a python selenium script (web scraper) on AWS Lambda. I really want to schedule my python (selenium) scripts but don't know how. Also, cron jobs somehow don't work for me on my own MacOS and I'd like to deploy on it on a remote server. I'd really love to see that. Keep the good work up! PS: Is there a way for under 18 y/o to get access to AWS?

  • @deadbearcode

    @deadbearcode

    3 жыл бұрын

    That's an interesting one! I haven't messed with Selenium much I may have to look into it. Lambdas are great for cron jobs you can pretty easily configure them to run when you want.

  • @ko-Daegu
    @ko-Daegu3 жыл бұрын

    5:58 the routers reminds me with flask blueprints

  • @prateeksrivastava7877
    @prateeksrivastava7877 Жыл бұрын

    Cool Video, thanks a lot, just want to know if we update our code, then do we need to follow all the steps from zip till upload?

  • @samarthhadawale4905
    @samarthhadawale49053 жыл бұрын

    Thank you so much for this awesome tutorial! I just had one question. Suppose I'm trying to get the data from my dynamoDB table using this FastAPI-Lambda function. What should I do next? Instead of receiving just the messages, I would like to invoke the data.

  • @deadbearcode

    @deadbearcode

    3 жыл бұрын

    Glad you liked it! There is a great AWS SDK for Python called Boto3. You can use Boto3 to interact with just about any AWS resource with Python. Here is an AWS walkthrough: docs.aws.amazon.com/amazondynamodb/latest/developerguide/GettingStarted.Python.html and here are the Boto3 docs: boto3.amazonaws.com/v1/documentation/api/latest/index.html

  • @samarthhadawale4905

    @samarthhadawale4905

    3 жыл бұрын

    @@deadbearcode Thank you so much for your help man! God bless you.

  • @climentea
    @climentea3 жыл бұрын

    It's less hassle with AWS Chalice framework

  • @demianpelos
    @demianpelos2 ай бұрын

    Isn't the point of lambdas server less that you don't need flask or fastapi? Is so you can develop locally in fast API and then deploy into lambdas? And Why do we need gateway? (Most of the time we do the app. Put Into a docker container and ecr) Super thanks for this tutorial :) the other way I have done is not a fast API is just a file with a function and I pointed the handler of lambda to that file/function inside the ZIP file

  • @ko-Daegu
    @ko-Daegu3 жыл бұрын

    At the end of the tutorial is really great but would be a bit better if you show us why are you doing what you are doing basically specially for those who’s new to Amazon AWS in general but I guess you assuming someone who knows enough Ans just want things up Ans running maybe

  • @deadbearcode

    @deadbearcode

    3 жыл бұрын

    Thanks for the watch. The big benefit is the savings on cost. With Lambdas you only pay for each request instead of paying for having an EC2 instance constantly running.

  • @snap-reviewsdotcom

    @snap-reviewsdotcom

    9 ай бұрын

    @@deadbearcode but Lambda functions have 2 restrictions: 30 second timeout and a 6MB data return limit. So this solution doesn't work for all use cases.

  • @vagifk2864
    @vagifk28642 жыл бұрын

    I have seen that they were puting uri routes inside of API gateway... here we used only one, defining routes within Lambda, just wandering which way is better?

  • @johnboscor
    @johnboscor Жыл бұрын

    /docs link doesn't work when deployed through api gateway. Any solutions for that?

  • @manoelramon8283
    @manoelramon8283 Жыл бұрын

    now comes the question... for real and high scalable application, would you really link your API gateway with a lambda considering the cost will be way higher than running uvicorn in a regular ECS or EC2?

  • @abdulrafay1951
    @abdulrafay19512 жыл бұрын

    That was quick, just a question. Lambda vs Nginx and PM2 Does it matter on which platform we want to host? Like is there could be any speed differences or anything else?

  • @drich188
    @drich188 Жыл бұрын

    Can you comment on the costs this type of deployment incurs? If I leave a connection open or am waiting for a backend function to return, am I gonna have a big bill waiting? Lambda is all about quick, small invocations right? Is there a safety measure worked in that addresses this?

  • @bindera_zlaya_nata
    @bindera_zlaya_nata3 жыл бұрын

    How it will work when 2 simultaneous requests arrived ? Any benefits from async/await and eventloop ?

  • @dbelliston
    @dbelliston3 жыл бұрын

    great stuff - curious if you looked into getting .zip size smaller? - its hitting about 10MB for me :(

  • @deadbearcode

    @deadbearcode

    3 жыл бұрын

    No, I haven't been able to look into that yet. Let me know if you figure something out! Is there a particular issue you're running into with the file size?

  • @JordanCote

    @JordanCote

    3 жыл бұрын

    Mine is hitting 30MB without much other dependencies

  • @TheDiscoMole
    @TheDiscoMole3 жыл бұрын

    Nice vid, but what is the point of FastAPI, doesnt the lambda spin up for each route request? Making it essentially synchronous?

  • @sanfilmstudio

    @sanfilmstudio

    3 жыл бұрын

    interesting quiestion, +

  • @nikilkvn

    @nikilkvn

    3 жыл бұрын

    +1

  • @abulfahadsohail466
    @abulfahadsohail466 Жыл бұрын

    Please anyone have idea while testing the fastapi on aws lambda I am getting module not found due to tkinter.?

  • @wesleyong2970
    @wesleyong29702 жыл бұрын

    I have quite many libraries in my python venv. As such my zip file exceeds the lambda deployment size limit :( Any workaround for this?

  • @nikhilk8454
    @nikhilk84543 жыл бұрын

    Good tutorial. But Rest API has a time out of 30 seconds. What should I do if my lambda takes more than 30 seconds to fetch some data like read data from a huge dynamodb table. Lambda has 15 min timeout but the api will timeout. How do we fix this. Please create a tutorial for this scenario.

  • @TeaSpoon2008
    @TeaSpoon20082 жыл бұрын

    How do you see the logs once you app is up on a lambda?

  • @firdousbhat3339
    @firdousbhat33392 жыл бұрын

    The actual lambda implementation starts at 8:08

  • @KG-dg4gt
    @KG-dg4gt2 жыл бұрын

    POST Method is Forbidden 403!!

  • @mchirag82
    @mchirag823 жыл бұрын

    Hey! I am not able to access the fastapi docs using this method. It says fetcherror "undefined/openapi.json" How can I enable that?

  • @johnboscor

    @johnboscor

    Жыл бұрын

    Were you able to figure this out? I am still strugging to find a solution

  • @ghlim592
    @ghlim5922 жыл бұрын

    hi thanks for sharing good tutorial can I ask one thing? "errorMessage": "Unable to import module 'app.main': No module named 'fastapi'", "errorType": "Runtime.ImportModuleError", "stackTrace": [] I have this error message after I run the proxy test. how can I solve it?

  • @bharatkundapur6067

    @bharatkundapur6067

    2 жыл бұрын

    same error for me aswell . Did you figure it out ?

  • @sanfilmstudio
    @sanfilmstudio3 жыл бұрын

    Whythere are so much folders such as api/api_v1/blabla? It's a rare case IRL, it may confuse the beginners.

  • @technicolourmyles
    @technicolourmyles3 жыл бұрын

    Is that your dog whimpering in the background?

  • @deadbearcode

    @deadbearcode

    3 жыл бұрын

    Haha! Yeah he was a puppy at the time. Although he still whimpers

  • @zameerahmed1775
    @zameerahmed1775 Жыл бұрын

    The music is irritating .... it distracts our attention.

Келесі