Page 1 of 1

IM7 on AWS Lambda

Posted: 2016-06-10T12:20:34-07:00
by fluxer
'AWS Lambda' is Amazon's microservice platform. You create a function in either Node.js or Python, connect it to an endpoint, this endpoint takes the payload of a request as input, processes this through the function, and returns a response (as well as executing any peripheral actions such as write to a database). You can read more about it here: https://aws.amazon.com/lambda/.

AWS Lambda comes with ImageMagick 6 pre-installed on their instances, which are running their own proprietary 'Amazon Linux' (appears to be a derivative of CentOS). Since there is no way to control the system or environment that the instances are launched with, one must include all function dependencies within their function code, including application binaries, as well as set any necessary environment variables to prepend search paths.

I have been using ImageMagick 6 just fine for the past few months, but have hit a situation where HDRI makes a significant difference in image quality. Thus, I have begun my quest in getting ImageMagick 7 to run on AWS Lambda.

What I've tried so far:
1. Boot up and access an EC2 Amazon Linux instance
2. Install the image delegates I need
3. Build ImageMagick 7 from source
4. Extract the 'magick' binary from /usr/local/bin (along with the appropriate symlinks)
5. Extract the /usr/local/lib libraries
6. Bundle the bin/ and lib/ directories into my AWS Lambda function code
7. Within my code, prepend the bin/ directory to $PATH, and prepend the lib/ directory to $LD_LIBRARY_PATH
(8. In case this is important, I also removed the static libraries to reduce total size)

With this setup, I made a simple test to check the output of 'convert -version', and this is the output:

Code: Select all

Version: ImageMagick 7.0.1-10 Q16 x86_64 2016-06-10 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2016 ImageMagick Studio LLC
License: http://www.imagemagick.org/script/license.php
Features: Cipher DPC HDRI OpenMP 
Delegates (built-in): freetype jng jpeg png tiff zlib
So far so good. However, when I try to actually do anything with it, this is the output I get:

Code: Select all

convert: UnableToOpenConfigureFile `configure.xml' @ warning/configure.c/GetConfigureOptions/709.
But, in my lib/ directory, it is there at

Code: Select all

lib/ImageMagick-7.0.1/config-Q16HDRI/configure.xml
Is the directory for configure.xml somehow hard-coded (not using $LD_LIBRARY_PATH)? If so, how can I fix that?

Re: IM7 on AWS Lambda

Posted: 2016-06-10T14:57:55-07:00
by fluxer
I see now that the `configure` option `--disable-installed` seems to be what I need. I cannot, however, find very much documentation on how this works exactly. Is the directory I build in using `make` the directory that the $MAGIC_HOME environment variable should be set to? can I prepend $MAGIC_HOME/utilities to my $PATH? Do I need to prepend anything to $LD_LIBRARY_PATH, or will the binary pick it up since the `--disable-installed` flag was set? What files inside this directory are completely necessary, and which ones can I remove safely?

Re: IM7 on AWS Lambda

Posted: 2016-06-10T19:49:50-07:00
by fmw42
Just a guess as I know little about installation on Linux, but perhaps you need to install the xml delegate library?

Re: IM7 on AWS Lambda

Posted: 2016-12-20T07:56:13-07:00
by stefandlt
@fluxer did you get this working? I have a similar requirement.