Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

133
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!