简体   繁体   中英

Optimize nodejs aws lambda

I have a nodejs lambda to get data from a url. When I began to develop it I had all the code in a single file and just required a single module installed via npm. Now I'm trying to make things a little bit clearer for futures developers and I am separating the code in several files. The plan is to zip all the files later. The case is that I don't know if this could cause a worst performance due to te require statements.

I've been thinking on use webpack to bundle all js files in a single file and serve it that way. It could be better?

The best way to find out is to give it a try. I'd say start with requiring because it will make the code and the process of deployment simpler, then if you notice performance issues try with Webpack and see if there are improvements. This sounds a little like premature optimisation.

Regarding the require statements - depends on how big the files you require are. In my experience, requiring modules in lambda hasn't had significant performance effects at all. I'd say the cold start will probably take a bit longer, but after that the modules will be cached for reuse and it will be all good.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM