serverlesspub / imagemagick-aws-lambda-2

ImageMagick for AWS Lambda 2 runtimes
https://serverless.pub
Other
259 stars 163 forks source link

Ask for update to lastest ImageMagick and Nodejs #51

Open daoanhthanh opened 11 months ago

daoanhthanh commented 11 months ago

The Nodejs v10 is no longer supported by AWS. Could you please update your layer to support node v20. I could not do it :((

ersel commented 11 months ago

I have done this recently for Nodejs v20 and arm chipset.

You can download the layer.zip from the archive here.

https://github.com/CyprusCodes/imagemagick-aws-lambda-2/tree/master/archive

daoanhthanh commented 11 months ago

@ersel I used the lastest gm to handle image processing. However, the lambda function returns this error:

2023-11-23T02:26:41.739Z    51ec5d98-e696-4659-bcc1-3c34b15abf1c    INFO    beforeResize <Buffer ff d8 ff e0 00 10 4a 46 49 46 00 01 01 01 00 48 00 48 00 00 ff e2 0c 58 49 43 43 5f 50 52 4f 46 49 4c 45 00 01 01 00 00 0c 48 4c 69 6e 6f 02 10 00 00 ... 849077 more bytes>
2023-11-23T02:26:54.111Z    51ec5d98-e696-4659-bcc1-3c34b15abf1c    INFO    afterResized <Buffer >
2023-11-23T02:26:54.133Z    51ec5d98-e696-4659-bcc1-3c34b15abf1c    INFO    toS3 <Buffer >
2023-11-23T02:26:54.190Z    51ec5d98-e696-4659-bcc1-3c34b15abf1c    ERROR   Unhandled Promise Rejection     {"errorType":"Runtime.UnhandledPromiseRejection","errorMessage":"TypeError: Cannot read properties of undefined (reading 'mime')","reason":{"errorType":"TypeError","errorMessage":"Cannot read properties of undefined (reading 'mime')","stack":["TypeError: Cannot read properties of undefined (reading 'mime')","    at toS3 (file:///var/task/services.js:88:28)","    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)","    at async file:///var/task/index.js:7:3","    at async handler (file:///var/task/index.js:6:9)"]},"promise":{},"stack":["Runtime.UnhandledPromiseRejection: TypeError: Cannot read properties of undefined (reading 'mime')","    at process.<anonymous> (file:///var/runtime/index.mjs:1276:17)","    at process.emit (node:events:514:28)","    at emit (node:internal/process/promises:150:20)","    at processPromiseRejections (node:internal/process/promises:284:27)","    at process.processTicksAndRejections (node:internal/process/task_queues:96:32)"]}

This happens because the gm library could not interact with ImageMagick's API, therefore the resize function's output is null as you can see in the log above in the second row. I used lambda node20 for ARM and your layer only.

Here is my code for using GM:

const gm = require("gm").subClass({ imageMagick: "7+" });
const resize = async (imageArrayBuffer, width, height = undefined) => {
    console.log("beforeResize", imageArrayBuffer);
    return await gmToBuffer(gm(imageArrayBuffer).resize(width, height)).then(
        (resizedImage) => {
            console.log("afterResized", resizedImage);
            return resizedImage;
        }
    );
};
...

Do you have any ideas about why it happens, please?

johnpc commented 7 months ago

@ersel how do I use the zip file that you've shared?

ersel commented 7 months ago

@johnpc upload the file as a Lambda Layer using the AWS dashboard

johnpc commented 7 months ago

Ah, I missed the part about how it requires arm. Is it possible to make an x86 version?