2

I am trying to create a thumb from a pdf file in a lambda, but when I create the image I get the following error:

Error: stream throws an empty buffer.

I have already increased to 300mb of lambda memory and it doesn't work.

const gm = require("gm").subClass({ imageMagick: true });
const fs = require("fs");

const params = {
  Bucket: sourceBucket,
  Key: originalNameImg,
};

const pdf = await s3.getObject(params).promise();

temp_file = mktemp.createFileSync(`/tmp/XXXXXX.pdf`);
fs.writeFileSync(temp_file, pdf.Body);
image = gm(temp_file + "[0]");

image.resize("400", "400").toBuffer("jpg", function(err, buffer) {
  if (err) {
    reject(err);
    return;
  } else {
    resolve();
  }
});

The nodejs version I am using is: Node.js 14.x

John Rotenstein
  • 241,921
  • 22
  • 380
  • 470
tanjiro
  • 81
  • 6

1 Answers1

0

you should install gm package that convert images in AWS AMI.

In latest AWI doesn't have the package.

use AWS layer

  • 1
    Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Dec 26 '21 at 09:20
  • Amazone Machine Images (AMI) is not about pictures. It is about instance images (OS, programs). An AMI could have GraphicsMagick. But it is possible to install it. And then make your own AMI. – PIoneer_2 Sep 13 '22 at 10:02