imagemagick-aws-lambda-2 icon indicating copy to clipboard operation
imagemagick-aws-lambda-2 copied to clipboard

Ask for update to lastest ImageMagick and Nodejs

Open daoanhthanh opened this issue 1 year ago • 5 comments

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

daoanhthanh avatar Nov 21 '23 06:11 daoanhthanh

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

ersel avatar Nov 22 '23 14:11 ersel

@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?

daoanhthanh avatar Nov 23 '23 02:11 daoanhthanh

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

johnpc avatar Mar 24 '24 03:03 johnpc

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

ersel avatar Mar 24 '24 18:03 ersel

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

johnpc avatar Mar 24 '24 23:03 johnpc