[Support Guide] How do I write a Javascript Lambda Function?

We recommend that you use the async keyword instead of a callback function when writing Netlify Functions in JavaScript. For example:

exports.handler =  async function(event, context) {
  console.log("EVENT: \n" + JSON.stringify(event, null, 2))
  return context.logStreamName

For posterity, the following non-async method using callback is still supported, but the async syntax is more versatile. An example of a callback function is below:

exports.handler =  function(event, context, callback) {
  https.get(url, (res) => {
    callback(null, res.statusCode)
  }).on('error', (e) => {

For more information regarding best practices, check out the Netlify docs on Functions.