Introduction to the JAMStack

What is a Serverless Function

Jason Lengstorf

Jason Lengstorf

Learn With Jason
Introduction to the JAMStack

Check out a free preview of the full Introduction to the JAMStack course

The "What is a Serverless Function" Lesson is part of the full, Introduction to the JAMStack course featured in this preview video. Here's what you'd learn in this lesson:

Jason talks about the practicability of serverless applications that only require a JavaScript function, and explains that this course will use Netlify as the serverless platform.


Transcript from the "What is a Serverless Function" Lesson

>> Let's go ahead and start diving into serverless functions. And so I'm gonna move out of our basic and I'm gonna move into contact here. Inside of contact, I have, really nothing. So let's just clear out and take a look. So in my contact folder, I have a bunch of stuff that I don't need.

We'll end up dealing with all that when it's time. So the only thing that we have right now is a dot and dot example. We'll get to that in a minute and why that's useful, but for now, we're just gonna start out with some simple functions. So a serverless function, the the biggest challenge that you'll hear when you start talking about the JAMstack, is that people will say, hey, I appreciate that this is fast and that this is easy, but you can't build a real app with this.

There's a pushback that static assets means that these are only good for static sites. And that is, I can understand where that objection comes from, because historically, that would be true. If I wanted to have anything more than a marketing site that shows some images and some cool information about a product or service, how do you do that?

How do you add interactivity or something? You would end up needing to stand up a server of some sort. And so while you could potentially call that a JAMstack site, because you would be calling your own API, functionally that would mean that you're still maintaining a server. You're now at a microservices level.

You've got a UI layer. And then you've got your API servers over here. So when we start looking at true JAMstack, serverless starts to overcome that objection that you can't do anything real with just the JAMstack. Because what serverless gives us is the ability to write just a little bit of JavaScript.

And then we don't have to maintain a server. We don't have to stand up an API to add that functionality, because all of that is abstracted away and managed, functions as a service. So the first thing that I wanna do here is let's just build the simplest possible serverless function and watch it work.

So I'm gonna create in this contact folder, a folder called functions. And then I want to create a hello.js. And we're gonna build a hello world, because that's what you gotta do whenever you're learning something new, right? So the format for a serverless function is gonna vary a little bit from service to service.

If you look around at the cloud providers today, pretty much all of them will have some variation of functions. You can do this through AWS has AWS Lambda, Google cloud functions, Azure functions, Zyte has functions as a service. I mean, honestly, any kind of cloud company is most likely going to have a lambda functions as a service offering.

We're going to use Netlify, because again, it's free and it's easy. If you use something like AWS, they have Amplify, which also makes this very easy. But it's not quite free, I don't think. I don't know. AWS is one of those things that I'm kinda carrying some preamplifier trauma around from, so I still am like, I wanna do it the easier way.

But I have to give a shout out to the Amplified team because they are doing a fantastic job of making AWS approachable. But today we're going to use Netlify. You can use whatever service you want there. There are lots and lots of options.

Learn Straight from the Experts Who Shape the Modern Web

  • In-depth Courses
  • Industry Leading Experts
  • Learning Paths
  • Live Interactive Workshops
Get Unlimited Access Now