Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it a good idea to use Python SQLAlchemy in AWS Lambda?

Amazon suggests to not include big libraries/dependencies in lambda functions. As far as I know, SQLAlchemy is quite a big python library. Do you think it is a good idea to use it in lambda functions? An option would be to include it as a Lambda Layer and use it across all related Lambda functions.

Anyways, what is the best practise?

like image 254
funtik Avatar asked Oct 11 '19 12:10

funtik


People also ask

Can we use SQLAlchemy in Lambda?

We add two utility source files to the Lambda layer in order to encapsulate SQLAlchemy components and make them reusable across the business logic Lambda functions: bookstore_orm_objects.py – This file holds the SQLAlchemy ORM objects and mappings ( Book and Review ).

Is SQLAlchemy worth using?

SQLAlchemy is the ORM of choice for working with relational databases in python. The reason why SQLAlchemy is so popular is because it is very simple to implement, helps you develop your code quicker and doesn't require knowledge of SQL to get started.

Is Python good for AWS Lambda?

The benefits of Python in AWS Lambda environmentsPython is without a doubt the absolute winner when it comes to spinning up containers. It's about 100 times faster than Java or C#. Third-party modules. Like npm, Python has a wide variety of modules available.


1 Answers

Serverless functions are meant to be small self-contained functions. SQLAlchemy is an ORM, which allows you to manipulate database objects like objects in python. If you're just writing a few serverless functions that do you're average CRUD operations on a database you're better off writing the SQL by composing the strings and directly executing that through your database driver (which you'll have to install anyways, even if you're using sqlalchemy). If you're building your own framework on top of AWS Lambda then perhaps consider sqlalchemy.

like image 60
Steven Black Avatar answered Sep 20 '22 19:09

Steven Black