I have an existing Django application data stored under Postgres RDS. Now I want to query/update the data via a lambda(AWS) function with Django style ORM.
I know in theory it is possible if,
User.objects.all()
)I wanted to know if anyone has done this? Examples or write-ups are much appreciated
In order to deploy a Django project on AWS Lambdas you should prepare your AWS infrastructure. There is a list of AWS services I use for my Django project: Lambdas to run our wsgi application. API Gateway to handle HTTP request and send them to Lambdas.
Django doesn't have a separate package for it's ORM, but it's still possible to use it on its own.
You can run Python code in AWS Lambda. Lambda provides runtimes for Python that run your code to process events. Your code runs in an environment that includes the SDK for Python (Boto3), with credentials from an AWS Identity and Access Management (IAM) role that you manage.
Use Django ORM for your Data Management tasks. Even without starting any web server. The extensive feature set of Django as a high-level Web framework can scare off Data Analysts and Data Scientists who never really had contact with Web development.
If you only want to use Django's ORM (no views, admin, templates), then yes, you can use Django ORM in AWS Lambda as a library and no need for Zappa.
You can see how to do it from here: Using only the DB part of Django
However, take note that in AWS Lambda, you are billed per 100ms of execution time and Django ORM is not exactly fast (vs. direct raw queries).
It is recommended that you keep your Lambdas as lean as possible. Loading up the entire Django package is opposite of that recommendation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With