2

Consider this Node 8.10 code:

exports.handler = async (event, context, callback) => { setTimeout(() => callback(null, "resolved"), 100) }; 

When I run it the response is null. When I remove the async keyword from the handler the response is "resolved" as expected.

Can anyone explain this behavior? How is the async function executed in a Lambda container and what is the difference in a "normal" function?

2
  • Are you sure it returns null and not undefined ? Commented Jun 26, 2018 at 7:33
  • In the test result I see Response: null. But even if it was undefined, the question is what is the difference in the execution? Commented Jun 26, 2018 at 7:47

1 Answer 1

3

The processing of an async function differs from a normal one.

Using a normal function, the Lambda container uses the callback function to get the result, even called asynchronously.

But when the handler is defined as async, the return value is taken: var res = await handler(...) and the callback ignored.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.