无法在AWS Lambda上将pdf转换为图像

时间:2019-07-20 00:50:46

标签: node.js aws-lambda imagemagick graphicsmagick pdf-conversion

我有一个Nodejs 8.10 lambda,它可以将pdf转换为png,直到几天前都可以正常工作。 这似乎是由于AWS更新引起的错误 https://aws.amazon.com/blogs/compute/upcoming-updates-to-the-aws-lambda-execution-environment/

{ 
Error: Command failed: convert -density 200 -quality 75 "/tmp/temp_file.pdf[0]" "/tmp/temp_file-0.png"
convert: unable to load module `/usr/lib64/ImageMagick-6.7.8/modules-Q16/coders/pdf.la': file not found @ error/module.c/OpenModule/1278.
convert: no decode delegate for this image format `/tmp/temp_file.pdf' @ error/constitute.c/ReadImage/544.
convert: no images defined `/tmp/temp_file-0.png' @ error/convert.c/ConvertImageCommand/3046.
}

通过添加此公共层解决了该错误,该公共层将在7月22日之后停止工作: arn:aws:lambda ::: awslayer:AmazonLinux1703

我尝试为AWS Lambda创建ImageMagick静态二进制文件。 我遵循了ImageMagic 6.9.10-5版本的这些说明 https://gist.github.com/bensie/56f51bc33d4a55e2fc9a

https://imagemagick.org/download/ImageMagick-6.9.10-55.tar.gz

lambda的文件夹结构:

enter image description here

我尝试了png图像的基本尺寸调整:

var IM_PATH = "var/task/imagemagick/bin/";
process.env['LD_LIBRARY_PATH'] = 'var/task/imagemagick/lib/';
process.env['PATH'] = process.env['PATH'] + ':' + IM_PATH + ':' + process.env['LD_LIBRARY_PATH'];

var gm = require('gm').subClass({
imageMagick: true,
appPath: 'var/task/imagemagick/bin/',
});

gm('image.png')
.resize(240, 240, '!')
.write('/tmp/resize.png', function (err) {
if (!err) console.log('done');
else {
console.log(err);
}
});

尝试在节点8.10和节点10.x lambdas上运行,并在此处显示错误:

1)节点8.10

{ Error: Command failed: convert: UnableToOpenConfigureFile `delegates.xml' @ warning/configure.c/GetConfigureOptions/677.
convert: NoDecodeDelegateForThisImageFormat `PNG' @ error/constitute.c/ReadImage/560.
convert: NoImagesDefined `/tmp/resize.png' @ error/convert.c/ConvertImageCommand/3235.

    at ChildProcess.onExit (/var/task/node_modules/gm/lib/command.js:301:17)
    at emitTwo (events.js:126:13)
    at ChildProcess.emit (events.js:214:7)
    at maybeClose (internal/child_process.js:925:16)
    at Socket.stream.socket.on (internal/child_process.js:346:11)
    at emitOne (events.js:116:13)
    at Socket.emit (events.js:211:7)
    at Pipe._handle.close [as _onclose] (net.js:567:12) code: 1, signal: null }

2)节点10.x

{ Error: Command failed: var/task/imagemagick/bin/convert: error while loading shared libraries: libgomp.so.1: cannot open shared object file: No such file or directory

    at ChildProcess.onExit (/var/task/node_modules/gm/lib/command.js:301:17)
    at ChildProcess.emit (events.js:189:13)
    at ChildProcess.EventEmitter.emit (domain.js:441:20)
    at maybeClose (internal/child_process.js:970:16)
    at Socket.stream.socket.on (internal/child_process.js:389:11)
    at Socket.emit (events.js:189:13)
    at Socket.EventEmitter.emit (domain.js:441:20)
    at Pipe._handle.close (net.js:597:12) code: 127, signal: null }

0 个答案:

没有答案