question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[aws-lambda-nodejs] document how to install native modules (was: Ability to run post install scripts when nodeModules are explicitely defined)

See original GitHub issue

Currently 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:closed
  • Created 3 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
hudsontavarescommented, Dec 21, 2022

I faced the same issues as @stevensnoeijen. Be aware that this is a Windows permission issue that can be solved using the following steps:

  • Remove your cdk.out folder (rmdir /s cdk.out)
  • Start your Docker Desktop as an Administrator and wait until the process is up and running
  • Start your terminal as an Administrator (Google how to do that)
  • Try to run cdk synth orcdk deploy your code again

P.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)

1reaction
jogoldcommented, Nov 12, 2020

Have a look at https://github.com/jogold/cdk-s3-thumbnail where I use sharp. It uses Docker bundling to build sharp in a Lambda compatible environment.

If you have Parcel installed and still to want to force Docker bundling you can set the forceDockerBundling prop to true.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Using Packages and Native nodejs Modules in AWS Lambda
In this post we take a look at how to use custom nodejs packages with ... point we've installed the 'aws-sdk' module into...
Read more >
How to load npm modules in AWS Lambda? - Stack Overflow
Put your Lambda function file(s) in a separate directory. · Install your NPM packages locally with npm install packageName while you're in your ......
Read more >
Webpack - Serverless Framework: Plugins
This plugin is for you if you want to use the latest Javascript version with Babel; use custom resource loaders, optimize your packaged...
Read more >
How To Use Node.js Modules with npm and package.json
js project. It is also commonly used to install a wide range of CLI tools and run project scripts. npm tracks the modules...
Read more >
aws-cdk.aws-lambda-nodejs - PyPI
Install modules. By default, all node modules referenced in your Lambda code will be bundled by esbuild . Use the nodeModules prop under...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found