aws / aws-lambda-nodejs-runtime-interface-client

Apache License 2.0
180 stars 56 forks source link

Reduce package size with bundling #51

Closed fromtheexchange closed 1 year ago

fromtheexchange commented 2 years ago

On https://github.com/fromtheexchange/aws-lambda-ric, I bundled aws-lambda-ric with @vercel/ncc to reduce the package size from 128M to 688K. Bundling reduced my final image size by 25%.

metaskills commented 2 years ago

WOW, coming from the Ruby side where it is a simple gem install with no system dependencies needed, this feels like something worth doing.

Maybe at the least the README here should speak more to a docker multi-staage build/installation approach?

jlarmstrongiv commented 2 years ago

WOW, coming from the Ruby side where it is a simple gem install with no system dependencies needed

That’s the ideal solution, hopefully this PR will be merged https://github.com/aws/aws-lambda-nodejs-runtime-interface-client/pull/8 and all native dependencies can be removed.

Maybe at the least the README here should speak more to a docker multi-staage build/installation approach?

While multi-stage builds are possible, I find there are drawbacks too. I have to spend much more compute time building the image (especially if I’m using the ARM architecture), and frameworks like serverless still upload all stages to AWS’s ECR service, which can be upwards of 4 gigs with the multi-stage builds.

https://github.com/fromtheexchange/aws-lambda-ric

That’s an interesting approach, using GitHub Actions to publish containers you can copy from to avoid building from scratch every time. Unfortunately, there’s still the issue of https://github.com/aws/aws-lambda-nodejs-runtime-interface-client/issues/44#issuecomment-1032928940, which means that the nodejs runtime interface client differs depending on whether you use docker containers or not (and prevents using ES Modules in the docker version).

Using the new AWS Linux 2022 is nice, but getting the right version of NodeJS installed is not straightforward https://github.com/nodesource/distributions/issues/1367#issuecomment-1199837646

@metaskills anyway, watch out for those hidden gotcha’s. I ended up building my own system to manage NodeJS C++ addons too.

metaskills commented 2 years ago

hopefully this PR will be merged https://github.com/aws/aws-lambda-nodejs-runtime-interface-client/pull/8 and all native dependencies can be removed.

Yup, but given the age I might have to solution something as well.

That’s an interesting approach

Fun fact, I do the same here for this Rust-based Lambda Extension https://github.com/customink/crypteia#installation and I think I can do something similar for our Ubuntu images.

krk commented 1 year ago

This is fixed in https://github.com/aws/aws-lambda-nodejs-runtime-interface-client/pull/70.