Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sharp on AWS Amplify Backend Lambda Causing Build to Fail

I am pretty new to aws amplify and have an amplify app that has a backend lambda function which uses sharp as a dependency. When I push to git to trigger a deploy, my build is failing I think due to vips/vips8 a sharp dependency not being found.

Relevant log

2022-05-31T18:26:18.714Z [INFO]: [0mError: Packaging lambda function failed with the error [0m
                                 [0mCommand failed with exit code 1: npm install --no-bin-links --production[0m
                                 [0msh: prebuild-install: command not found[0m
                                 [0m../src/common.cc:24:10: fatal error: vips/vips8:  [0m
                                 [0m #include <vips/vips8>[0m
                                 [0m          ^~~~~~~~~~~~[0m
                                 [0mcompilation terminated.[0m
                                 [0mmake: *** [Release/obj.target/sharp-linux-x64/src/common.o] Error 1[0m
                                 [0mgyp ERR! build error [0m
                                 [0mgyp ERR! stack Error: `make` failed with exit code: 2[0m
                                 [0mgyp ERR! stack     at ChildProcess.onExit (/root/.nvm/versions/node/v14.19.0/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:194:23)[0m
                                 [0mgyp ERR! stack     at ChildProcess.emit (events.js:400:28)[0m
                                 [0mgyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:282:12)[0m
                                 [0mgyp ERR! System Linux 4.14.246-187.474.amzn2.x86_64[0m
                                 [0mgyp ERR! command "/root/.nvm/versions/node/v14.19.0/bin/node" "/root/.nvm/versions/node/v14.19.0/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"[0m
                                 [0mgyp ERR! cwd /codebuild/output/src927006233/src/create-react-app-auth-amplify/amplify/backend/function/S3Trigger71b5b76d/src/node_modules/sharp[0m
                                 [0mgyp ERR! node -v v14.19.0[0m
                                 [0mgyp ERR! node-gyp -v v5.1.0[0m
                                 [0mgyp ERR! not ok [0m
                                 [0mnpm WARN [email protected] No repository field.[0m

Running amplify push from my windows box packages up the lambda and deploys it working totally fine, the problem is only when it pulls from github and tries to run through the amplify build platform. I am running node v 16

Thanks for any ideas! My google-foo is failing me this time.

like image 842
Turner Avatar asked Jun 10 '26 19:06

Turner


1 Answers

According to the installation guide for AWS Lambda you can add the following command as the preinstall script to the package.json of your Amplify lambda:

{
  "name": "file-storage-get-s3-signed-link",
  "version": "1.0.0",
  "main": "index.js",
  "scripts": {
    "preinstall": "SHARP_IGNORE_GLOBAL_LIBVIPS=1 npm install --arch=x64 --platform=linux --libc=glibc sharp"
  }
}
like image 189
Aleksandr Sakharov Avatar answered Jun 12 '26 09:06

Aleksandr Sakharov



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!