DEV Community

Tomasz Łakomy
Tomasz Łakomy

Posted on • Edited on • Originally published at tlakomy.com

AWS (?) made simple: What is a Netlify function?

Before we start - I'm working on https://cloudash.dev, a brand new way of monitoring serverless apps 🚀. Check it our if you're tired of switching between 50 CloudWatch tabs when debugging a production incident.


~Simple~

Let's face it, AWS (a.k.a "the cloud") is not simple.

Even though some AWS services have the world 'simple' in their name (e.g. S3, SQS, SNS) they are anything but simple.

I'm personally trying my best to level the playing field by learning AWS Lambda in public but still, serverless functions are not simple and may be extremely confusing for a beginner.

Even in my egghead.io AWS Lambda collection we're able to actually call the lambda function via a GET request only after the third lesson in the series. Not to mention that we're manually creating an API Gateway and the thing is that maybe you don't even want to know what an API Gateway is?

Maybe you're just trying to solve a problem with a serverless function without getting a PhD in AWS?

I want to create a function, ship it somewhere and call it via an API, why is this so confusing? 😿

Serverless made painless

Netlify Functions homepage

"Severless made painless" is the goal that Netlify Functions team had in mind while developing that service.

In my humble opinion, they've managed to do it right.

What they do is that they abstract AWS Lambda away from you.

In other words, with Netlify functions you're literally only responsible for providing the code - the rest is configured, provisioned, deployed, scaled and tested (okay, without that last one - write tests pls) for you.

Note: if you find this kind of tech interesting I'd still recommend you to learn AWS Lambda but here's a thing - it's just a recommendation.

You don't have to learn AWS in order to start using serverless functions. Better yet - an AWS account is not required at all!

How do I do that?

Allow me to present you a "How do I create a Netlify Function" tutorial:

  1. In your app/site hosted by Netlify, create a functions directory
  2. Inside of that directory create a hello.js file:
exports.handler = async function(event, context) {
    return {
        statusCode: 200,
        body: 'Witaj świecie!', // Our function is Polished 🇵🇱
    };
};
Enter fullscreen mode Exit fullscreen mode
  1. Deploy the site

THAT'S IT

Your function is now deployed and can be called from the outside! Give it a shot

What happens behind the scenes? I'm glad you asked!

Netlify is going to:

  • deploy your code to AWS (to be more precise - to us-east-1 AWS region)
  • it'll provide the function with 1024MB of memory (so your dreams of running Slack with Lambda are over, apologies)
  • and a 10 second execution limit (more than enough time to execute even my code which is more often than not slow or terrible, sometimes both).
  • make sure that your function can be called from the Internet by setting up an API Gateway in front of it

I'm a huge fan of solutions like this.

The kind where you get to solve your problem without reinventing the wheel when you're just trying to get some work done.

I'm not (yet?) an expert on Netlify Functions but from what I can see, they have lots and lots of interesting use cases and I'm definitely giving them a shot!

A screenshot of netlify function use cases

(I'm especially going to dive into Netlify Identity because manging auth is NOT fun)

Top comments (0)