Home > Enterprise >  Django backend on aws lambda : what is considered a request?
Django backend on aws lambda : what is considered a request?

Time:05-11

Im considering setting up a django backend on aws lambda and i need to calculate the costs based on the number of requests and duration of these requests. How can I calculate the number of requests in django (ie what is considered in django as an aws lambda request)? Is a page requested equivalent to a request in aws lambda? Or is a database access equivalent to one request ? How can I compute the average duration of a request? THank you

CodePudding user response:

One HTTP request from the browser to your server equals one Lambda request. Whatever your Lambda function (Django) does internally (like queries to the database) just increases the runtime of the function invocation and thus the billed time, it's not a "request".

If you're serving a website, the browser may make a whole lot of requests to the server for each individual CSS stylesheet, Javascript file, images and the like. When hosting on Lambda, I'd recommend this setup:

  • use Zappa to deploy to Lambda
  • use Django's collectstatic command to collect static files, and deploy them to S3; there's no need to serve static files through a Lambda function
  • put a CloudFront in front of your S3 bucket to serve static files blazingly fast
  • Related