1

I'm suing GraphicsMagick in a Lambda function with Node and I'm getting this error:

Could not execute GraphicsMagick/ImageMagick: gm "convert" "/tmp/yH3Js6ALXVGGAokvIsij.png" "/tmp/a086ffd7-a143-4f83-8f6a-fcdd29b12630.png" this most likely means the gm/convert binaries can't be found
at ChildProcess.<anonymous> (/var/task/node_modules/gm/lib/command.js:232:12)
at emitOne (events.js:96:13)
at ChildProcess.emit (events.js:188:7)
at Process.ChildProcess._handle.onexit (internal/child_process.js:213:12)
at onErrorNT (internal/child_process.js:367:16)
at _combinedTickCallback (internal/process/next_tick.js:80:11)
at process._tickDomainCallback (internal/process/next_tick.js:128:9)

So it says the gm/convert binaries can't be found which means the app isn't installed although the line "gm": "^1.23.1" is in package.json. Can you tell me now I can include the gm/convert binaires in the repo to make it work? Thank you!

Lee Maan
  • 699
  • 3
  • 10
  • 30

2 Answers2

3

gm is a NodeJS package for using ImageMagick. You still need ImageMagick itself.

You would need to install and compile ImageMagick for the Lambda environment. You can then upload it as a Lambda layer where your Lambda Function can sit on top of.

If you use serverless, you can take a look at this answer that provides you the steps on how to build ImageMagick as a Lambda layer.

Noel Llevares
  • 15,018
  • 3
  • 57
  • 81
  • Jeez a lot of commands! He's talking about executing this code in the server, right? Does he mean he wants to include all this code in a bash file and let Lambda execute it upon deployment for example? (I can't comment on his answer). – Lee Maan Dec 18 '18 at 08:10
  • 2
    No. You execute in a Linux machine to create the Lambda layer. If you're in Mac OSX or Windows, you have to use `docker` or `vagrant` to have to create a Lambda-compatible layer. Then, deploy that Lambda layer. Then, configure your Lambda Function to run on top of that Lambda Layer. – Noel Llevares Dec 18 '18 at 19:17
  • Thanks for the answer! I got AmazonLinux running in a Docker container but I am still having difficulty understand how to do the rest done (get ImageMagick with all delegates, extract binaries from container, use them as a layer in AWS Lambda...). Is there any reference you can share apart of the bit and pieces we find in Google search? – Lee Maan Dec 20 '18 at 09:09
0

There is a static build of ImageMagick that you can deploy directly from this page. https://serverlessrepo.aws.amazon.com/applications/arn:aws:serverlessrepo:us-east-1:145266761615:applications~image-magick-lambda-layer

Deploying will create a Lambda layer that you can then use in your Lambda function.

Note that you will still need the GraphicsMagick node.js library, which you can build on an Amazon Linux 2 AMI instance by running the following commands:

sudo yum update
curl -sL https://rpm.nodesource.com/setup_10.x  | sudo bash -
sudo yum install nodejs
mkdir nodejs
cd nodejs
npm init
npm install gm
cd ..
zip -r nodejslayer.zip ./nodejs

That zip file can then be directly uploaded to create a second Lambda layer. Both the ImageMagick and GraphicsMagick Lambda layers are necessary to successfully run your Lambda function.

alenz
  • 84
  • 8