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

131
Vistas
Request in lambda Node.JS doesn't work timeout

I am modifying a function in nodejs 14 in aws lambda, The code will fetch a json and then do other tasks:


const https = require('https');
var http = require("https");
var AWS = require('aws-sdk');


exports.handler = async (event, context, callback) => {
    console.log('Event: ', JSON.stringify(event, null, 2));
    const request = event.Records[0].cf.request;



const https = require('https');
const http_get = require('https');

var options = {
    host: 'www.local.dev',
    method: 'GET',
    timeout: 2000,
    path: '/list.json',
    headers: {
        'Accept': 'application/json'
    }
};



const res = await new Promise(resolve => {
  http_get.get(options, resolve);
});


let data = await new Promise((resolve, reject) => {
  let data = '';
  res.on('data', chunk => data += chunk);
  res.on('error', err => reject(err));
  res.on('end', () => resolve(data));
});

data = JSON.parse(data)

// CONTINUE FUNCTION 

    return request;
};

I would like to set a timeout if the request to fetch the json doesn't return in 2 seconds., I continue the function, The function has other parts, so even if nothing comes from the json endpoint it can continue.

It has no dependency on the json return.

What is happening and that the timeout is not validated and the function is running indefinitely.

I need to use this http module from node.js, I can't use axios here.

To simulate the timeout I am using this app: httpstat.us/501?sleep=60000

about 4 years ago · Juan Pablo Isaza
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