I think the AWS Lambda docs are misleading, but I wanted to check here first.
Their doc https://docs.aws.amazon.com/lambda/latest/dg/nodejs-prog-model-handler.html states that "If your code performs an asynchronous task, return a promise to ensure that it finishes running." And their code examples all demonstrate returning a promise directly. This seems to indicate that the following would be incorrect:
exports.handler = async (event) => {
const data = await somePromise();
return data;
};
But in reality this works perfectly fine. I feel like their doc entirely misses the point of async/await - if you're going to return a promise, then you don't actually need to mark your function as async, right?
Edit: What I'm looking for is a direct answer on whether the specific assertion that "If your code performs an asynchronous task, return a promise to ensure that it finishes running." is incorrect. I'm fairly sure of the answer, but wanted to get confirmation from a javascript expert, such that I can include this SO post if I contact AWS to get the doc updated. I feel that this is fairly important, given that Lambda enables a lot of JS novices to easily run JS code, and so the advice/boilerplate they're given should be better.