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

281
Views
AWS Lambda - NodeJS - nested Await / Async not returning

Having this small Lambda-Function:

module.exports.handler = async( data , ctx, cb) => {
 console.log("start");
 createSth();
};


async function resolveAfter2Seconds(x) {
  console.log("in function: " + x);
  return new Promise(resolve => {
    setTimeout(() => {
      resolve(x);
    }, 2000);
  });
}

async function createSth() {
  var x = await resolveAfter2Seconds(10);
  console.log(x); // 10
}

I would have expted the following output

start
in function: 10
10

But I only get

start
in function: 10

So everything after var x = await resolveAfter2Seconds(10); is not executed.

It works outside of aws lambda in a similar setup.

Thanks.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Add await keyword while calling createSth function. This will allow main function to wait for the execution of the function and won't return

i.e.

module.exports.handler = async( data , ctx, cb) => {
    console.log("start");
    await createSth();
};
about 4 years ago · Juan Pablo Isaza Report
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!