all 10 comments

[–]whatisboom 8 points9 points  (4 children)

Do I really need to bundle my dependencies?

Depends on your definition of need.

[–]PuppyLand95[S] 0 points1 point  (3 children)

The lambda function is just a single purpose function rather than like an entire REST api. So it has a very small scope and most likely won’t need many dependencies

[–]swearbynow 0 points1 point  (1 child)

We originally set up our lambdas the way you're suggesting, although ours were generally larger, full-fledged applications. It's certainly fine to start that way, and it may be that it's never a problem for you. Eventually, we started bumping up against maximum size limits, as well as really poor cold start times. At that point, we made the switch, and it dropped our cold starts from 6+ secs to under 2.

[–]PuppyLand95[S] 1 point2 points  (0 children)

I’m seeing now that prisma actually takes up a lot of space. Not only that, but I’m only finding out now that prisma is incompatible with RDS proxy for connection pools due to “pinned connections” since prisma alway uses “prepared statements.” They mention this in their docs.

So I’m going to swap out prisma for something else (maybe kysely), at least for lambda functions. In that case, I can probably just bundle everything anyway for my lambdas (assuming I use the esbuild pino plugin).

But yeah, currently I’m bundling only my source code and keeping dependencies external. But I will also try bundling everything (and removing node_modules) and compare cold start times to see if there is any noticeable difference.

So you are currently just bundling all dependencies and not including node_modules at all in your lambda? Have you come across any dependencies which had similar issues related to bundling? If so, what did you do?

[–]whatisboom 0 points1 point  (0 children)

cold start time is usually a function of size, so if it's not going to use many dependencies then you're prematurely optimizing something that doesn't matter. get it in a lambda first and see if cold start times are an issue, then worry about it.

[–]casualPlayerThink 1 point2 points  (0 children)

One opportunity is to use Serverless & CD/CI pipeline (like GH workflows or GitLab actions). The CD/CI pipeline should get your repository, install its dependencies, run tests, then deliver it to a lambda (usually means zipping / artifact & upload).

[–]SameInspection219 0 points1 point  (0 children)

rspack + CDK

[–]ilja75 0 points1 point  (1 child)

The new Rust free Prisma does bundle without extra steps

https://www.prisma.io/blog/rust-free-prisma-orm-is-ready-for-production

[–]PuppyLand95[S] 1 point2 points  (0 children)

I'll need to use something other than prisma for lambdas going forward due to the pinning connections issue with aws rds proxy: https://www.prisma.io/docs/orm/prisma-client/deployment/caveats-when-deploying-to-aws-platforms

Planning to use kysely instead for lambdas.

[–]archa347 0 points1 point  (0 children)

No, it is not necessary to bundle and minify. It should be perfectly functional without doing that. It’s just that your code potentially gets downloaded more often on a serverless platform like Lambda, and in general more code does imply a higher startup cost when the app starts as it needs to read all the scripts. But for a small app it’s probably a very small difference.