Browse Chapters
A serverless function is a program written to handle one request per program execution. In other words, the program is started, handed a request, and run only until that request is handled. Then it is shut down.
Earlier in the guide, we saw an example of a simple serverless function written in JavaScript:
const encoder = new TextEncoder()
// Declare a function that handles a request (in this case, an HTTP request)
export async function handleRequest(request) {
// Send back an object that describes a response (in this case, an HTTP response)
return {
status: 200,
body: encoder.encode("I'm a Serverless Function").buffer
}
}
The entry point of a serverless function is (act surprised when I say this) a function. More specifically, it is a function that gives the request input and returns a response as output optionally.
We call this kind of program a serverless function. It does not start a server that listens for requests. It does not run for long periods.
The serverless function is the building block of what we will look at next: the serverless app. There we will talk about how some platforms, like AWS Lambda, use the terms “serverless function” and “serverless app” interchangeably. And in most cases, that is fine.
Browse Chapters