jeremydaly / lambda-api

Lightweight web framework for your serverless applications
https://serverless-api.com
MIT License
1.41k stars 125 forks source link

Question - Using Lambda-api with MySQL #185

Closed bschwarz closed 1 year ago

bschwarz commented 3 years ago

I am trying to use Lambda-api, and almost all of my routes will access a MySQL database (AWS RDS). Do you have a recommendation on how to set this up properly? I tried to wrap the DB connection and queries in a class that gets called from the routes, but it isn't working. Do you have any examples with Lambda-api using MySQL?

davthedev commented 2 years ago

This is what I am doing and I actually need to write some code to do the handover from the API to the database. This is how I can do data validation, check for required fields, etc... before handing over to the database.

Sequelize is my my preferred ORM for that. I use an Aurora Serverless instance running MySQL and the Data API to avoid the complex management of "traditional" RDS connections that involves networking configuration. It also helps lowering costs in comparison to a full-blown permanent RDS instance.

To use the Data API, you need to plug specific connectors to Sequelize such as this one: https://www.npmjs.com/package/@fyreware/mysql-data-api

naorpeled commented 1 year ago

Hey @bschwarz, First of all, sorry for the huge delay.

lambda-api currently doesn't have any add-ons out of the box for database queries, but I can recommend some libs that you can use:

I'll be closing this issue but if you have any further questions, feel free to ping me.