0

I have a Nodejs 8.10 lambda which converts pdf to png which was working fine untill few days ago. This is the error which seems to be caused because of AWS update 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.
}

The error was resolved by adding this public layer which will stop working after July 22: arn:aws:lambda:::awslayer:AmazonLinux1703

I tried creating ImageMagick Static Binaries for AWS Lambda. I followed these instructions for ImageMagic version 6.9.10-5 https://gist.github.com/bensie/56f51bc33d4a55e2fc9a

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

Folder structure for lambda:

enter image description here

I tried basic resize of png image:

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

Tried running on Node 8.10 and node 10.x lambdas and here the the errors:

1) Node 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) Node 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 }
coolgarcon
  • 31
  • 8
  • Looks like Ghostscript might not be installed. It is needed to read PDF files. Does `convert -version` list gs or gslib? Does `convert -list format` list an entry for PDF? If neither, then Ghostscript would not seem to be installed. If it shows both, then it is possible that the new version came with an entry in the policy.xml file that restricts the use of PDF/PS/EPS files. You would then have to change the entry. See https://stackoverflow.com/questions/52861946/imagemagick-not-authorized-to-convert-pdf-to-an-image/52863413#52863413. – fmw42 Jul 20 '19 at 02:31
  • Duplicate -- see https://stackoverflow.com/questions/57067351/imagemagick-not-converting-pdfs-anymore-in-aws-lambda – fmw42 Jul 20 '19 at 02:33

0 Answers0