ORM/Validation Best Practice for Connecting Lambda to AWS RDS
Basically the title:
I am connecting Lambda functions to RDS Aurora (PostgreSQL). This is the backend for a mid-sized web app and a backend with ~20 tables.
I am debating wether to use an ORM.
Benefits:
- Decoupling data layer from code
- Assistance with database migrations as the app scales
- Assistance with validation/serialization
Concerns
- I am worried about the extra overhead of including an ORM in Lambda functions.
I've bounced between SQL Alchemy -> Marshmallow -> None (just psychopg2)
Complicating my decision, is that I am using the PostGIS extension of PostgreSQL to do some geo queries.
What do you think Reddit, is the overhead of an ORM worth it in a serverless app?
Posted Dec 21, 2019, 10:47 PM UTC
14
I have a lot of mixed feelings about an ORM but it seems like you want to use many of the advanced features of it. I would say go for the ORM as long as you know the gotchas of using it and you know what it’s doing under the hood.
What are your mixed feelings? As of right now, I'm leaning towards not using one. I am happily collecting all relevant opinions.
I’ve just seen too many cases where developers used ORMs and created bad, non performing queries. It’s easy to shoot yourself in the foot for instance using EF and do a foreach loop over an IQueryable that causes database access on each loop iterations.
But if it’s a personal project and just you, go for it. Whatever makes your life easier.