Functions common to several lambda

Advertisements

I have a project under NodeJS and hosted on AWS, and I have several functions that I would like to use in several lambdas, without having to copy and paste. Currently, I run a shell at build time that copies all these files, but the drawback is that all the packages I use must also be installed in all these lambdas.

So I’d like to know if there’s a much cleaner way of doing this or not.

PS: The build is done via Github Actions

>Solution :

You can either:

  • Use Lambda layers so that you can freeze the dependency versions, reduce the weight of each lambda and avoid repetitive code base. It allows you to reduce the repetitive code on functions that would utilize it. One downside though is that if something gets messed up inside the layers, the importing functions will all get affected.
  • Bundle, minify and treeshake your NodeJS (Easier to implement in TypeScript) functions before deploying them to AWS lambda.

Leave a ReplyCancel reply