pre-compiled sharp is compatible with Lambda environment
mooyoul opened this issue · comments
starting sharp v0.20.0, it provides pre-built libvips binaries & supports installing specific platform / arch via npm_config_arch
or npm_config_platform
environment variable.
so we can install required native dependencies using following command: env npm_config_arch=x64 npm_config_platform=linux npm_config_target=8.10.0 npm install
on packaging step. (target version should be matched to actual node.js runtime version. in this case, targets Lambda Node.js 8.10 runtime)
I'm using this method to deploy our lambda functions without building native deps for lambda environment, and it works like charm without having any issues :)
Hi @mooyoul , I would also be interested in this. Do you have a link to an example?
@einSelbst just remove locally installed sharp and re-install sharp by executing following command on packaging step: npm rm sharp && env npm_config_arch=x64 npm_config_platform=linux npm_config_target=8.10.0 npm install sharp
. (please note that target node.js runtime version is v8.10.0, so you should use Node.js 8.10 Lambda runtime or change value of npm_config_target
to your lambda runtime version ;)) prebuilt libvips will be installed automatically by sharp's own postinstall script.
References:
- lovell/sharp@430a429 (See install/libvips.js file)
Thank you @mooyoul . Unfortunately I still had the same error, that some sharp dependency wasn't available.
I tried it like this:
# serverless.yml
...
custom:
webpack:
includeModules:
forceExclude:
- aws-sdk
- serverless
packager: 'yarn'
packagerOptions:
scripts:
- npm rm sharp && env npm_config_arch=x64 npm_config_platform=linux npm_config_target=8.10.0 npm install sharp
(and several versions of it) I think I stay with the docker based approach for now.