AWS Lambda not working with gm module

I use AWS Lambda to resize my image in s3 bucket to different size options using node js when the image fits in s3 bucket .

He worked until yesterday. Today, when I use the same lambda function, I get the following error:

{ "errorMessage": "Command failed: identify: not authorized `//bucketname.s3.amazonaws.com/imagename.jpg' @ error/constitute.c/ReadImage/454.\n", "errorType": "Error", "stackTrace": [ "", "ChildProcess.proc.on.onExit (/var/task/node_modules/gm/lib/command.js:297:17)", "emitTwo (events.js:87:13)", "ChildProcess.emit (events.js:172:7)", "maybeClose (internal/child_process.js:821:16)", "Socket.<anonymous> (internal/child_process.js:319:11)", "emitOne (events.js:77:13)", "Socket.emit (events.js:169:7)", "Pipe._onclose (net.js:469:12)" ] } 

I cannot understand why this phenomenon occurred. All of the above functions of my lambda function below are in async waterfall , to first calculate the aspect ratio, and then convert the image to different size options.

 var request=require("request"); function getTheAspectRatio(callback) { gm(s3Url) // I am constructing the image url in the AWS Lambda Function. .size(function(err, size) { if (!err) { //Calculate the Aspect ratio } else if (err) { //Give Back the Error } }); } function getTheImageBuffer(callback) { request(imageUrl, function(err, res, res1) { if (err) { callback(err); } else { buffer = res1; console.log("got the BUffer"); callback(null); } }); } function convertToThumbNail(callback) { //Convert to Thumbnail Image } function convertToFull(callback) { //Convert to Full Image } function convertToBadge(callback) { //Convert to Badge image } 

Can someone help in debugging the problem? I’m kind of stuck on this for the last 3 hours. My AWS Lambda is located in the Tokyo region.

+6
source share
5 answers

I had the same error message in a process that ran flawlessly in the last 5 weeks. After a conversation with AWS support, I was told today that due to a vulnerability recently discovered here, https://imagetragick.com/ , support for the native library for Imagemagick was removed from AWS Lambda.

I was told that I would have to rebuild my Lambda function and bundle in my own version of the native library - https://aws.amazon.com/blogs/compute/nodejs-packages-in-lambda/

A support representative confirmed that there was no public announcement of this change.

TL; DR: if you used the AWS Lambda function, which depended on the Imagemagick version, from 04/05/2016, it is now broken and probably will not work until you reinstall its self-supported version of the library. May the fourth be with you ...

+10
source

Mitch Shields is correct, now you need to build / deploy it yourself on AWS Lambda.

I created a version that works for my project, and a NodeJS tool that downloads it to the lambda instance. The built-in tarbal ~ 85mb, which is too large to pack with your code, so you need to download it to lambda before starting it. It is stored in /tmp/imagemagick , lambda is trying to cache the /tmp/ folder, so you do not need to download it every time you start.

GitHub Page: https://github.com/DoubleDor/imagemagick-prebuilt

Check out releases for tarab ImageMagick builds https://github.com/DoubleDor/imagemagick-prebuilt/releases

+3
source

According to AWS documentation: http://docs.aws.amazon.com/pt_br/lambda/latest/dg/current-supported-versions.html AWS Lambda still supports imagemagick.

However, I had the same problem a few days ago when the project worked flawlessly. Since the problem with the error message causes a resolution conflict when trying to read the S3 bucket, not the image problem.

You can try changing Bucket permissions Create a bucket in Amazon S3 .

As a workaround, you can always loop image files with a lambda file and avoid such conflicts.

+1
source

https://alas.aws.amazon.com/ALAS-2016-699.html

"Note: This update contains an updated /etc/ImageMagick/policy.xml file that disables the codecs EPHEMERAL, HTTPS, HTTP, URL, FTP, MVG, MSL, TEXT and LABEL"

I changed my call from gm(my_url) to gm(request(my_url)) and it seems like everything works again. Ie I'm sending a stream from the request () call to ImageMagick instead of letting ImageMagick try to load the image (which is disabled in ImageMagick policy.xml, a file that I cannot change).

+1
source

It seems that your Lambda function does not have access to your S3 bucket. Make sure your function has an appropriate IAM policy, for example:

 { "Version": "2012-10-17", "Statement": [{ "Effect": "Allow", "Action": [ "s3:GetObject", "s3:PutObject" ], "Resource": [ "arn:aws:s3:::*" ] }] } 

Although your problem has nothing to do with graphics, note that AWS Lambda only comes with imagemagick installed. Therefore, if you do not provide graphicsmagick executables, be sure to use an external class:

 var gm = require("gm").subClass({ imageMagick: true }); 
-one
source

All Articles