Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

653
Vistas
File is missing when trying to resize in Sharp in AWS Lambda function

I am sincerely puzzled by this. I am simply trying to invoke a Lambda function from within a Node JS application and perform image resizing on it. The invocation succeeds and the function is called (I can pass parameters to it and see them returned), however when I attempt to use Sharp for image resizing, I get the strange error that the input file is missing. It's not, as I can definitively confirm that the buffer is indeed passed to the Lambda.

I can confirm that using Sharp locally works. In the invocation I am JSON stringifying the payload, and I can confirm that the parameters are indeed passed to and are received by the Lambda. I am mapping them correctly from the first 'event' argument in the invocation. However the inclusion of Sharp within the Lambda just simply breaks.

I have created a new 'Sharp' project and have installed the node modules. These are packaged with the Lambda's index function into an archive and this is uploaded into the zip. The one thing that is quite different is that in order to use Sharp inside of Lambda, I had to install the linux version.

npm install --arch=x64 --platform=linux sharp

I have a test script in the Lambda where I have copied over a complete payload including a proper buffer. Both the test script and my local machine throw the same error:

{
  "errorType": "Error",
  "errorMessage": "Input file is missing",
  "trace": [
    "Error: Input file is missing"
  ]
}

This is my Lambda function.

const sharp = require('sharp');

exports.handler = async (event) => {
  return await sharp(event.buffer)
    .resize({
      width: event.maxWidth,
      height: event.maxHeight,
      fit: 'inside',
      withoutEnlargement: true
    })
    .jpeg({
      quality: 80
    })
    .toBuffer();
}

And this is my invocation.

const thumbImage = await lambda.invoke({
   FunctionName: 'sharp-resize',
   Payload: JSON.stringify({ buffer: file.buffer, maxWidth, maxHeight })
}).promise();

Any ideas or assistance would be appreciated.

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

I finally figured this out, and it really was such a simple thing. When chaining the buffer, Lambda needed to recreate the buffer from the event.buffer property. When the function returned the resized image, I chained it again before recreating the buffer on receipt. Then it was a simple matter of posting the new buffer to S3.

My final lambda:

 const sharp = require('sharp'); exports.handler = async (event) => { let buffer = Buffer.from(event.buffer.data); buffer = await sharp(Buffer.from(buffer)) .resize({ width: event.maxWidth, height: event.maxHeight, fit: 'inside', withoutEnlargement: true }) .jpeg({ quality: 80 }) .toBuffer(); } return { statusCode: 200, headers: { "Access-Control-Allow-Origin": "*" }, buffer: JSON.stringify(buffer) }; }

And my invocation and post to S3:

 const thumbImage = await lambda.invoke({ FunctionName: 'sharp-resize', Payload: JSON.stringify({ extension, buffer: file.buffer, maxWidth, maxHeight }) }).promise(); const payload = JSON.parse(thumbImage.Payload); const buffer = JSON.parse(payload.buffer); const parsedBuffer = Buffer.from(buffer.data); response.thumbImage = await uploadToS3({ key: amazonS3ThumbKey, file: parsedBuffer });
over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda