Chase Fenske
Chase Fenske

Reputation: 138

AWS node js lambda using gm imagemagick resize, crop and monochrome getting timeout

My lambda function watches s3, gets object and crops/resizes to desired sizes, then uploads. I do have the lambda layer for imagemagick, and I've had some success with resize, but it works maybe 10% of the time. These are my imagemagick functions,

exports.resizeImg = async (buf, width, height) => {
  return new Promise((resolve, reject) => {
    gm(buf).resize(width, height).noProfile().toBuffer((err, buffer) => err ? console.log(err) : resolve(buffer));
   });
};

exports.cropImg = async (buf, width, height) => {
  return new Promise((resolve, reject) => {
    gm(buf).crop(width, height, 0, 0).noProfile().toBuffer((err, buffer) => err ? reject(err) : resolve(buffer));
   });
};

exports.monochromeImg = async (buf) => {
  return new Promise((resolve, reject) => {
    gm(buf).monochrome().noProfile().toBuffer((err, buffer) => err ? reject(err) : resolve(buffer));
   });
};

calling the resize or crop as

const resized = await resizeImg(buffer, 200, 200);

then passing the binary/buffer to s3 upload, which is working. If resize works.

I've also tried to write the buffer to fs, but no luck there either.

 exports.resizeImage = async (buf, width, height, path) => {
     gm(buf)
     .resize(width, height, "!")
     .write(path + 'output/1111.jpg', function(err){
     if (err) return console.dir(arguments)
     console.log(this.outname + " created  ::  " + arguments[3])
      })
  }

Does imagemagick still work? Or should I just use sharp?

Upvotes: 0

Views: 437

Answers (1)

Justin Joseph
Justin Joseph

Reputation: 3899

i have same error i fix with incress the timeout time

new aws UI

lambda function -> configuration -> General configuration -> Edit Timeout

enter image description here

Upvotes: 2

Related Questions