11

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,

  • Package the whole Django library with the lambda function(zipped)
  • Declare all the models inside package
  • Start using Django ORM as we do normally (Ex User.objects.all() )

I wanted to know if anyone has done this? Examples or write-ups are much appreciated

Noel Llevares
  • 15,018
  • 3
  • 57
  • 81
nehem
  • 12,775
  • 6
  • 58
  • 84
  • [Zappa](https://github.com/Miserlou/Zappa) – Kevin Christopher Henry Sep 01 '17 at 04:29
  • @KevinChristopherHenry Actually, I've explored Zappa, I don't you why you think it's something we should consider here. – nehem Sep 01 '17 at 04:34
  • You asked if anyone has done this and asked for write-ups. Lots of people are doing that using the Zappa framework, and the documentation links to various articles and write-ups. If I'm misunderstanding you, perhaps you can clarify more precisely what it is you're trying to do. – Kevin Christopher Henry Sep 01 '17 at 06:05
  • As the title is clear enough I'm trying to use Django ORM statements inside a lambda function in order to access the database. For ex `User.objects.filter(name='xxx yyy')` should return a list of users from the `auth_user` table. If you are familiar enough with Django ORM syntax you can understand what I'm trying to achieve here. – nehem Sep 01 '17 at 06:32
  • Zappa is a tool designed to do exactly what you're asking for. If your "exploration" led you to think otherwise you might want to take another look. – Kevin Christopher Henry Sep 01 '17 at 07:47
  • 2
    You'll need Zappa if you want to use most of Django's features inside AWS Lambda. There's no need for Zappa if you only want the ORM. – Noel Llevares Sep 03 '17 at 17:58

1 Answers1

14

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.

Noel Llevares
  • 15,018
  • 3
  • 57
  • 81