zoellner / sharp-heic-lambda-layer

Lambda Layer providing sharp with HEIC support
MIT License
69 stars 71 forks source link

Lambda layer does not work #30

Closed Cruaier closed 6 months ago

Cruaier commented 6 months ago

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?

zoellner commented 6 months ago

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

Cruaier commented 6 months ago

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

zoellner commented 6 months ago

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
Cruaier commented 6 months ago

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 commented 6 months ago

@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

zoellner commented 6 months ago

Thank you. will give that a try

zoellner commented 6 months ago

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