According to the blog post on Netlify Functions 2.0 (Netlify introduces new Functions capabilities), if you wish to use the CLI to scaffold new functions, you should ensure your CLI is updated to 16.6.2 or higher. This morning I updated to 17.9.0, scaffolded a new function, and the code used was 1.0, despite a comment on top though talking about 2.0:
// Docs on event and context https://docs.netlify.com/functions/build/#code-your-function-2
const handler = async (event) => {
try {
const subject = event.queryStringParameters.name || 'World'
return {
statusCode: 200,
body: JSON.stringify({ message: `Hello ${subject}` }),
// // more keys you can return:
// headers: { "headerName": "headerValue", ... },
// isBase64Encoded: true,
}
} catch (error) {
return { statusCode: 500, body: error.toString() }
}
}
module.exports = { handler }