Image Magick with Jets on Lambda


#1

I am trying to figure out how to package a binary to do simple image resizing in Lambda with Jets. I couldn’t find anything on this topic and was wondering if you guys had any insight?

Using something like gem 'image_magick' for the resizing.


#2

I’m not a Lambda expert, but I think you can add a Lambda Layer with the image_magick executable and configure Jets to use it.

https://rubyonjets.com/docs/extras/custom-lambda-layers/
https://docs.aws.amazon.com/lambda/latest/dg/configuration-layers.html

This layer might be what you’re looking for:

Let me know if you are successful, it would be great to add an example to the Jets docs.


#3

Ah, you’re right. That sounds like a great idea. And they even have a nice little way to do it :smiley:

https://serverlessrepo.aws.amazon.com/applications/arn:aws:serverlessrepo:us-east-1:145266761615:applications~image-magick-lambda-layer

Now I need to see if it is possible with Jets to apply the layer only to one function. That’d be great.


#4

Good news! You probably don’t need an extra lambda layer after all.

I dug a little deeper and discovered that the Linux image that is used by AWS Lambda for Ruby already has a version of Image Magick.

https://aws.amazon.com/amazon-linux-ami/2018-03-packages/

My guess is that you should be able to make it work as long as the gem you are using is simply using the executables, e.g. mini_magick.

Good luck!


#5

Huh thats weird because my code was failing at the convert methods. I was using mini_magick’s combine_options and nothing was ever returned not even a peep of an error. I assumed it was the binary or something.


#6

Huh that’s annoying.

I didn’t test the mini_magick gem, but I wrote a simple controller that printed all executables in all folders in ENV['PATH'], and convert was there.

Maybe you can play around with MiniMagick.configure to help it find the executables?

Sorry, I wish I could help more.