12

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

6
  • Zappa Commented Sep 1, 2017 at 4:29
  • @KevinChristopherHenry Actually, I've explored Zappa, I don't you why you think it's something we should consider here. Commented Sep 1, 2017 at 4: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. Commented Sep 1, 2017 at 6: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. Commented Sep 1, 2017 at 6:32
  • 3
    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. Commented Sep 3, 2017 at 17:58

1 Answer 1

16

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.