Should I keep all of my business logic in layers in AWS lamda functions service?

0

I am designing an application and I really haven't worked with lamda earlier. Currently I have service repository pattern implemented and I am running my application in an express http server.

Current design pattern -

Model - Sequelize models to call the db methods on

Repository layer - Communication with the Database through models

Service layer - calls to repository layer and implementation of business logic

Controller layer - Call service layer functions and send json response

Now I want to migrate to AWS lambda functions. I came accross usage of layers in lambda to share the code accross all the functions. Is it good design to put all my repositories, services and models in layers and only instantiate related classes and then invoke the functions from the lambdas ?( So lambdas will work like controllers in my current design)

Or should I move my entire business logic to lambda functions? The question is due to a blog that I read where I got to know that with every new deployment of layers I'll have to redeploy all the lambdas.

Please help!

2 réponses
2
Réponse acceptée

Although both can work, my recommendation would be to place all your code into the Lambda function. One of the factors that affects cold start time is package size. The package size incudes all the layers. By having all the code in a layer and including it in all functions, you pay extra cold start times for all functions. You should create smaller functions that each includes only what they need. Also, if you make a change to the business logic in one component, you will need to update all functions, which just adds to complexity.

You should use layers for things like common 3rd party libraries that you need to use across all functions. Things like monitoring.

profile pictureAWS
EXPERT
Uri
répondu il y a un an
  • Thank you for the help. I am seeing how over using the layers can cause problems in the production in the future. I am going to have repositories and 3rd party utility functions in layers and business logic in lambda functions.

1

Also would like to add that by default you're limited to five layers per lambda. So if you have a sizeable app (i.e. more than a couple models) you likely won't be able to attach everything you would need to the lambdas that need to do the processing.

https://docs.aws.amazon.com/lambda/latest/dg/invocation-layers.html

répondu il y a un an

Vous n'êtes pas connecté. Se connecter pour publier une réponse.

Une bonne réponse répond clairement à la question, contient des commentaires constructifs et encourage le développement professionnel de la personne qui pose la question.

Instructions pour répondre aux questions