Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AWS Lambda not working along with the gm module

I am using AWS Lambda to resize my image in s3 bucket into different size variants using node js when an image is put into the s3 bucket.

It was working till 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 am unable to understand why this phenomenon occurred. All the given functions of my lambda function below are in async waterfall to first compute the aspect ratio and then convert the image into different size variants.

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 somebody help in debugging the issue? I am kind of stuck on this for the past 3 hours.My AWS Lambda is in Tokyo Region.

like image 839
shubhamagiwal92 Avatar asked May 05 '16 09:05

shubhamagiwal92


People also ask

Could not load Lambda handler function due to error Cannot find module AWS SDK?

The "Cannot find module" occurs when a lambda function is trying to access a module which is not available in the function's execution runtime. The most common causes for the error are: zipping the wrong files, e.g. zipping a directory instead of the contents of the directory.

Which TCP port traffic is blocked in AWS Lambda?

TCP port 25 traffic is also blocked as an anti-spam measure. Q: How do I create an AWS Lambda function using the Lambda console? If you are using Node.

How do I resolve the unable to import module error that I receive when I run Lambda code in Python?

To resolve this error, create a deployment package or Lambda layer that includes the libraries that you want to use in your Python code for Lambda. Important: Make sure that you put the library that you import for Python inside the /python folder.


2 Answers

I had the exact same error message occur on a process that had been running flawlessly for the last 5 weeks. After speaking with AWS support today, I was informed that native library support for Imagemagick was removed from AWS Lambda due to the vulnerability that was found recently documented here https://imagetragick.com/.

I was told 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/

The support representative confirmed that there had not been a public announcement of this change.

TLDR: If you had been using an AWS Lambda function that was dependent on the bundled in version of Imagemagick, as of 05/04/2016, it is now broken and probably will not work until you redeploy with your own built and maintained version of the library. May the fourth be with you...

like image 50
Mitch Shields Avatar answered Nov 07 '22 14:11

Mitch Shields


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

I have built a version that works for my project, and a NodeJS tool that will download it onto the lambda instance. The built tarbal is ~85mb, which is too large to package with your code, so you have to downloaded it onto lambda before running. It is stored in /tmp/imagemagick, lambda attempts to cache the /tmp/ folder, so you shouldn't need to download it on every run.

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

Check the releases for the tarbal of the build ImageMagick https://github.com/DoubleDor/imagemagick-prebuilt/releases

like image 42
frenchie4111 Avatar answered Nov 07 '22 13:11

frenchie4111