[aws-lambda-nodejs] document how to install native modules (was: Ability to run post install scripts when nodeModules are explicitely defined)
See original GitHub issueCurrently NodejsFunction takes care of installing defined nodeModules and uploading assets to s3 but it will be nice to also be able to define post install scrips.
Use Case
I am trying to bundle a handler that makes use of Sharp
which has node execs “.node” in it’s distribution, but since parcel currenty doesn’t support bundelling “.node” files (as long as I am aware), I tried it as having an installed node_module by specifying
nodeModules: ['sharp'],
but this won’t work as is, because my development machine uses libvs based on darwin distribution and lambda requires linux based. As documented in sharp this can be resolved by reinstalling/rebuilding sharp for linux platform as
postinstall: npm rebuild sharp --arch=x64 --platform=linux sharp
Proposed Solution
NodejsFunction props to accept postInstal scripts along with nodeModules and applying it to npm postinstall script.
- 👋 I may be able to implement this feature request
- ⚠️ This feature might incur a breaking change
This is a 🚀 Feature Request
Issue Analytics
- State:
- Created 3 years ago
- Comments:8 (4 by maintainers)
Top GitHub Comments
I faced the same issues as @stevensnoeijen. Be aware that this is a Windows permission issue that can be solved using the following steps:
cdk synth
orcdk deploy
your code againP.S.: Windows is so pesky that it will not work if you open the terminal as an admin BEFORE Docker is running (it was true on my side Windows box at least)
Have a look at https://github.com/jogold/cdk-s3-thumbnail where I use
sharp
. It uses Docker bundling to buildsharp
in a Lambda compatible environment.If you have Parcel installed and still to want to force Docker bundling you can set the
forceDockerBundling
prop totrue
.