Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

136
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda