2

I'm trying to setup a Lambda layer to add a watermark to images with Graphicsmagick. I'm however a bit stuck at getting the binary to work with the libraries, so how do I setup a link to the libraries within the child process?

So far I've built the Graphicsmagick binary with the following options:

./configure --prefix=/opt/graphicsmagick --enable-shared=no --enable-static=yes --disable-shared --disable-installed 

Pretty much followed the instructions on this answer and ideas from this Gist. Either one however does not concern running binaries as a layer. So wondering maybe there are some specifics to that which I'm missing here?

Heres the code from my handler:

module.exports.run = async (event, context, callback) => {

  process.env['IM_PATH'] = '/opt/graphicsmagick/bin/'
  process.env['LD_LIBRARY_PATH'] = '/opt/graphicsmagick/lib'
  process.env['DYLD_LIBRARY_PATH'] = '/opt/graphicsmagick/lib'
  process.env['MAGICK_HOME'] = '/opt/graphicsmagick/'

  ...

  const graphicsmagick = '/opt/graphicsmagick/bin/gm'
  const graphicsmagickArgs = [
    '-dissolve', '15',
    '-tile',
    watermark,
    inputImage,
    output,
  ]

  spawn(graphicsmagick, graphicsmagickArgs, { stdio: 'inherit' })
    .on('close', () => console.log('success'))
    .on('error', error => console.log('error', error))

  ...

}

I've also tried running an exec with the environment variables like so:

exec('/opt/graphicsmagick/bin/gm', { env: 
  {
    'IM_PATH': `/opt/graphicsmagick/bin/`,
    'LD_LIBRARY_PATH': '/opt/graphicsmagick/lib',
    'DYLD_LIBRARY_PATH': '/opt/graphicsmagick/lib',
    'MAGICK_HOME': `/opt/graphicsmagick/`,
  }}, (err, stdout, stderr) => {
    console.log('error', err)
    console.log('stdout', stdout)
    console.log('stderr', stderr)
})

The layer runs Graphicsmagick but does not find the libraries folder. I get the following error in the console:

/opt/graphicsmagick/bin/gm: error while loading shared libraries:libpng15.so.15: cannot open shared object file: No such file or directory
samuelweckstrom
  • 209
  • 4
  • 14

0 Answers0