I was taking a look at the lambda function examples in the netlify-lambda github repo (you’ll have to scroll down a bit to see what I am referencing) and there seem to be two styles, the traditional callback style:
exports.handler = function(event, context, callback) {
// your server-side functionality
callback(null, {
statusCode: 200,
body: JSON.stringify({
message: `Hello world ${Math.floor(Math.random() * 10)}`
})
});
};
and the async/await style:
export async function handler(event, context) {
return {
statusCode: 200,
body: JSON.stringify({ message: `Hello world ${Math.floor(Math.random() * 10)}` })
};
}
I tried out the traditional style and it works fine for me, but when I do the async/await style I get the error Function invocation failed: SyntaxError: Unexpected token 'export'
.
Am I doing something wrong?