Hi team, I’m new with Serverless Stack and wonderi...
# help
c
Hi team, I’m new with Serverless Stack and wondering how I should structure my project. Currently I have an Express API with models, controllers, and services. For the models I’m using Sequelize ORM, these models are used in different services. My question is about how should I reuse my models and services in my functions (controllers)? Should I create functions for every model and call them from my services? Should I create functions for every service and call them from my controllers? I’ll use AWS Lambda functions, NodeJS and MySQL An example, tutorial, blog… will be appreciated Thanks in advance
s
The Lambdas are your controllers. You should attach them to some routing service (ApiGateway, AppSync, etc.). For the mysql database you need a db service (RDS, Aurora). Maybe you can benefit from the aws database migration service for a smooth transition if you are in production already. IMO you can implement an ORM as classes and use them in the Lambdas.
c
So the “only” thing I should do is make every controller a function and still importing my services and models (as share libraries) in those functions as I do with Express, right?
j
Yup that's roughly right. The controllers are the entry points for your routes.