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

649
Vistas
AWS Lambda does not execute the promises without await

I have the following handler for my AWS Lambda function. I don't want to or need to wait for Promise.all resolve or reject. Because, I am not interested about its result. My purpose is to just send those requests and finish. The problem is that if I remove the await keyword (pointed with an arrow), the requests are not firing up. But, if I put the await keyword, the Lambda function needs to run and be charged for 3-5 seconds, and it is not cost effective for me.

Could you explain what I am doing wrong? Why the requests are not being sent without the await keyword?

module.exports.handler = async (event) => {
  try {
    const urls = [/*some API urls*/];
--> await Promise.all(urls.map((url) => {
      return axios.post(url, { email })
        .catch((error) => {
          console.log(error);
        });
    }));

    return {
      statusCode: 200,
      body: JSON.stringify({ message: 'OK' }),
      headers: {
        'Content-Type': 'application/json',
      },
    };
  } catch (error) {
    return {
      statusCode: 500,
      body: JSON.stringify({ message: 'INTERNAL_ERROR' }),
      headers: {
        'Content-Type': 'application/json',
      }
    }
  }
};
over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

As stated in the docs

If your code performs an asynchronous task, return a promise to make sure that it finishes running. When you resolve or reject the promise, Lambda sends the response or error to the invoker.

If you don't return a promise, there is no guarantee your async tasks will run to an end. With making the handler async you are indeed returning a promise. But without awaiting the Promise.all this promise from the handler is immediately resolved, and thus execution of your lambda (and all unfinished async tasks) is stopped.

And this seems quite logical. Otherwise everybody would write the heavy lifting computations in an async task which runs for a long time. And the only synchronous call in the lambda function would be calling that async task and the lambda function would return after (and be charged for) only a few milliseconds.

If you want to pay only for a 100ms, make your task fast enough. If you task takes 4 seconds, you have to pay for 4 seconds.

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