Serverless compute services

Natasha Ong
This is some text inside of a div block.
4 min read

In a nutshell:

Serverless compute lets you run code without provisioning or managing servers, automatically scaling to handle your application's workload.
AWS Lambda lets you upload your code and configure it to run based on triggers. It can run code for up to 15 minutes at a time.
AWS Fargate lets you run your containers on top of a serverless compute platform. It is the alternative to hosting your containers on EC2 instances.

So as we've learnt, EC2 offers flexibility, reliability, and scalability - but you are responsible for a lot of the set up and management too. Think handling patching, scaling, and ensuring high availability. This is not as much work as on-premise servers, but management processes will still need to be in place.

We then learnt about containers, which offer efficiency and portability. AWS' container services are Amazon Elastic Container Service (ECS) and Amazon Elastic Kubernetes Service (EKS). Both ECS and EKS can run on top of EC2.

But what if you want to keep it even more hands free - what if you want to skip having to manage those EC2 instances?

That's where AWS Fargate comes in. Fargate is a serverless compute platform for ECS or EKS. But before we dive into Fargate, let's understand what serverless means.

What is serverless?

The term “serverless” means your code still runs on servers, but you won't need to create or manage these servers. In fact, you can't even see or access the underlying infrastructure or instances that are hosting your application.

AIl the management (creating, ensuring high availability, and maintenance) is taken care of for you. Another benefit of serverless computing is that it can scale your applications automatically.

You only need to focus on creating your application. What a dream!

AWS offers multiple serverless compute options. AWS Lambda is an iconic serverless compute option that's considered one of AWS' top services.

AWS Lambda

AWS Lambda is a service that lets you run code without needing to provision or manage servers.

Here's how it works:

1. You upload your code into a Lambda function.

*A function is like a recipe in programming. It's a set of instructions that you can use to do a specific task, like adding numbers, sorting a list, or sending an email. You can use it over and over to save time and make your code more organised.

2. Configure a trigger* and from there, the service waits for the trigger.

*A Lambda trigger is like a switch that turns on a small piece of code when a specific event occurs. This event could be things like a file upload, a database change, or a website visit. When the trigger event happens, the code does its job and then turns off until the next trigger.

3. When the trigger is detected, the code is automatically run in an environment that is automatically scalable, highly available and all of the maintenance covered by AWS. For example, a simple Lambda function might involve automatically resizing uploaded images uploaded to S3. In this case, the function triggers when it detect a new uploaded image.

Because Lambda's functions are triggered by changes in data, user activity, or some event you define, people often use the word event-driven to describe Lambda.

Key facts about Lambda

  1. Whether you have one or 1,000 incoming triggers, Lambda will scale your function to meet demand.
  2. Lambda is designed to run code under 15 minutes, so this isn't for long running processes. It's more suited for quick processing like a website's backend, where each invocation* takes less than 15 minutes to complete.
*An invocation = each time you trigger a Lambda function to run its code.

3. While using AWS Lambda, you pay only for the compute time that you use.

- Charges apply only when your code is running.

- In the previous example of resizing images, you would pay only for the compute time that you use when uploading new images. Uploading the images triggers Lambda to run code for the image resizing function.

AWS Fargate

AWS Fargate is a serverless compute service for containers. It works with both Amazon ECS and Amazon EKS, making it easy to run containers at scale.

  • When using Fargate, you do not need to create or manage servers. Fargate manages your server infrastructure for you
  • You can focus more on innovating and developing your applications, and you pay only for the resources that are required to run your containers.

Example scenario: Imagine you’re developing a chat app that requires real-time messaging capabilities. With AWS Fargate, you can deploy a containerised chat server. Fargate automatically manages the container resources, scaling up or down based on the number of active users. This ensures seamless communication and eliminates the need for manual infrastructure management.