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?
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 ).
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.
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.
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.
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