将Graphicsmagick作为AWS Lambda层运行

时间:2019-01-18 20:34:04

标签: node.js aws-lambda graphicsmagick

我正在尝试设置Lambda层,以通过Graphicsmagick向图像添加水印。但是,我在使二进制文件与库一起工作时有些卡住,那么如何在子进程中设置指向库的链接?

到目前为止,我已经使用以下选项构建了Graphicsmagick二进制文件:

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

基本上遵循了此answer上的说明和此Gist上的想法。但是,任何一种都不与将二进制文件作为层运行有关。所以想知道也许我在这里缺少一些细节吗?

从我的处理程序中获取代码:

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))

  ...

}

我还尝试过使用环境变量运行exec,如下所示:

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)
})

该图层运行Graphicsmagick,但未找到库文件夹。我在控制台中收到以下错误:

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

0 个答案:

没有答案