sharp-heic-lambda-layer icon indicating copy to clipboard operation
sharp-heic-lambda-layer copied to clipboard

Lambda layer does not work

Open Cruaier opened this issue 1 year ago • 4 comments

Hi there,

I tried out the Lambda layer following your build script but I am getting an error running the example code of this repository:

{
  "errorType": "Error",
  "errorMessage": "Input buffer contains unsupported image format",
  "trace": [
    "Error: Input buffer contains unsupported image format",
    "    at Sharp.metadata (/opt/nodejs/node_modules/sharp/lib/input.js:486:17)",
    "    at getFileMetadata (/var/task/index.js:1351:40)",
    "    at Runtime.handler (/var/task/index.js:1377:26)",
    "    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)"
  ]
}

The steps I did for the build were:

sam build --use-container --build-image public.ecr.aws/sam/build-nodejs20.x:latest - zip the build output and load it into a Lambda layer; create a Lambda function with the content of the examples layer and test it. I have a very similar build script for building a Lambda layer which also doesn't work for me (see ticket https://github.com/lovell/sharp/issues/4081).

Do you was able to test the Lambda layer with the latest versions?

Cruaier avatar Apr 26 '24 04:04 Cruaier

Yes, I am using the latest version in production. Since the error message mentions an unsupported image format I'd need to have the original image file to be able to test

zoellner avatar Apr 26 '24 08:04 zoellner

I used the test file you provided in this repository. Are you willing to share your Lambda layer artifact with me? I am attaching mine for reference if you want to have a look: https://we.tl/t-WGA5jgpGFc

Cruaier avatar Apr 26 '24 09:04 Cruaier

I can confirm that it does not actually work. My tests were running against an old version.

I thought it might be the missing x265 which I added in 4.1.0 but it still doesn't work. No idea why. vips 8.15.2 is compiled with libheif HEIC/AVIF load/save with libheif : YES (dynamic module: YES) and sharp detects the lib

sharp: Detected globally-installed libvips v8.15.2

sharp: Attempting to build from source via node-gyp
sharp: Found node-addon-api
sharp: Found node-gyp version 10.1.0

zoellner avatar Apr 26 '24 11:04 zoellner

The compilation itself works; you can test it e.g. inside the build docker container without issues (both sharp and vips). I assume the issue is with the packaging. If I have more time I'll investigate further.

Cruaier avatar Apr 28 '24 09:04 Cruaier

@zoellner I think the issue for you might be the same as in my script; the preset for libheif has to be changed during the compilation to "release-noplugins" in order to create a static build.

You can also have a look at my code for the sharp-heif layer here: https://github.com/Dobe-Solutions/sharp-heif-lambda-layer

Cruaier avatar Apr 30 '24 13:04 Cruaier

Thank you. will give that a try

zoellner avatar Apr 30 '24 14:04 zoellner

Had to make a few more tweaks but seems to work now. Thanks again for debugging

zoellner avatar Apr 30 '24 20:04 zoellner