New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Native modulse for Sharp, Installing modules in lambda docker #396
Comments
Hi @danielstaleiny , interesting question 👍 . I will investigate the docs and see how their intentions are about a working deployment/installation and how that would play together with serverless-webpack. At anyone coming here who frequently uses native modules (or lambda docker) or sharp, feel free to add your thoughts. |
Quick update: I fetched some infos from their website:
This could mean that we only have to add the correct binary to the webpack package and use node-loader to make it work. Amazon Linux should be no problem. |
@HyperBrain Can you please point me to docs where I can dive into setting these options ? :)) some examples anything. I would like to get moving with this otherwise I have to deploy it without serverless framework. :)) I appreciate you to having a look at this. |
I think you have to add the Then we need to make it build the linux version instead of the one for the local environment - for the rebuild script you have to set the proper node target version: # serverless.yml
custom:
webpack:
packagerOptions:
scripts:
- npm rebuild sharp --target=8.10.0 --target_arch=x64 --target_platform=linux Finally, include the Webpack copy plugin into your webpack configuration to include the binary folder from sharp to your package. Sorry that I could not go into details right now, I'm just writing this without having it tested myself (especially the rebuild command line, so you might need to test and fix that) - I'm currently at work and do not have very much time. Maybe someone who also uses native modules and added related issues here can help out. @janthonyeconomist, I think you also used a native node module and integrated that. Maybe you can help out here 😃 . Thanks. |
Sorry. I don't think I can be much help. I ended up going with a pure JS version of the library https://www.npmjs.com/package/maxmind to avoid the problem. |
We use sharp in https://github.com/keboola/developer-portal and the deployment is run in Docker. The image inherits from |
Ok. Then you even might not need the "rebuild" script configuration as the install of the native module already fetches the correct version. Just the node-loader and the copy plugin to include the files should work then. |
Thank you guys, works like charm. @JakubMatejka is Python27 needed in dockerfile ? and what does
do ? |
@danielstaleiny Great! Python is a prerequisite for |
I thought so, thank you Jakub. Closing this issue :) |
hi @danielstaleiny sorry for digging this issue. I'm also having the same problem. |
Here is simplify version of the JakubMatejka solution to this problem. You just need to package your function in docker. https://github.com/danielstaleiny/serverless-example |
thanks a lot @danielstaleiny ! |
Be careful on node-gyp issues with yarn. Everything worked for me and suddenly one day I woke up to continue working on my project and node-gyp failed to rebuild. After some digging I updated node-gyp version to latest 3.x which supposed to work with node 10.x and resolved my issue. I came back to yarn and it still failed to rebuild. After some digging I found that yarn has some issues with node-gyp and libraries like sharp, node-canvas. To resolve issues with node-canvas using node-gyp I was forced to use npm. (and also make sure that your default python executable is 2.xx not python 3.xx) 1 day wasted. Happy hacking guys. |
Question
Description
Hi I am trying to make sharp work with serverless and webpack plugin. I keep hitting the error
module initialization error: Error
. I suspect it is because sharp lib uses native and that is why it needs to be installed in lambda docker. Is there way to set up this workflow ?Reference to sharp note:
http://sharp.dimens.io/en/stable/install/#aws-lambda
How should be a workflow to correctly bundle this ?
I tried to do it manually but webpack plugin re-bundled it on deployment. Any help is appreciated.
I am on 5.1.5 of Serverless-webpack
and Serverless 1.27.2
The text was updated successfully, but these errors were encountered: