Serverless In AWS (AWS Serverless)

Rukmal Senavirathne
4 min readDec 17, 2023

What is Serverless?

Serverless is a new paradigm in which the developers do not have to manage servers. Initially Serverless == FaaS (Function as a Service) Now it is a lot more. Serverless does not mean there are no servers, it means we do not manage / provision and we don’t see them.

Why do we need Serverless?

For modern applications, we need to run reliable and scalable servers. The servers we must manage and monitor. Using serverless we can reduce complexity, reduce time, and we can reduce the cost of running a scalable and reliable server.

Serverless in AWS

· AWS Lambda

· DynamoDB

· AWS Cognito

· AWS API Gateway

· AWS S3

· AWS SNS and SQS

· AWS Kinesis Data Firehose

· Aurora Serverless

· Step Functions

· Fargate

Figure 1

AWS DynamoDB

· DynamoDB is a NoSQL database.

· It is cloud native.

· Distributed Database.

· Fully managed and highly available database with replication across multiple AZs.

· Millions of requests per second. 100s of TB of storage.

· Everything is integrated with IAM. So, for security, authorization, and administration, it’s low cost.

· We do not need a database it’s already there we only need to create a table.

There are two types of tables.

1. Standard — for frequently accessed data.

2. IA — for infrequently accessed data.

· Each table has a primary key. We can decide on the primary key when we create the table. After that, we can add data

· Different data types are supported such as String, Number, Binary, Boolean, Null, list, maps, and sets.

There are two modes.

1. Provision mode (default) — we can define how many reads and writes going to do with the table. RCU and WCU (Read Capacity Units and Write Capacity Units). Autoscaling will increase RCU and WCU automatically.

2. On-Demand –Capacity will scale automatically with the workload. It is expensive as a solution and amazing for unpredictable workloads.

AWS Lambda

let’s take an example, AWS EC2. AWS EC2 is a virtual server in the cloud and we have to provision them, so we are limited by the amount of memory and CPU we’re going to provision.

EC2 must be continuously running, we can optimize them by starting them and stopping them efficiently, but otherwise, EC2 runs continuously, regardless of whether something’s happening or not on instance. If we want to scale, we can use auto-scaling groups, but that means that we need to do something to automatically add and remove servers.

Now, this is one way of doing things and it has worked great.

But then there is AWS Lambda with Lambda, these are visual functions. No servers to manage which means that we just provision the code and the functions run.

It is limited by time up to 15 minutes and runs on-demand. That means that when we don’t use Lambda, the Lambda function is not running and, only going to be billed when the Lambda function is running. it will run on demand when it gets invoked, which is a huge shift from Amazon EC2. The scaling is automated.

The language supports for Lambda.

· node.js, for JavaScript

· Python

· Java

· C# for .NET Core

· Golang

· C# for Powershell

· Ruby

API Gateway

Let’s assume we have a functionality with a lambda function and DynamoDB as shown in Figure 1. Then clients want to do CRUD operations through the Lambda function.

There are multiple ways to do that,

· Invoke lambda directly. For this client needs IAM permission.

· Use application load balancer between client and lambda function.

· Expose lambda function as an HTTP endpoint.

· Invoke using API Gateway.

API Gateway is a serverless offering from AWS. Which allows to creation of REST APIs that can be accessed publicly for clients. It provides more features than HTTP endpoint such as,

· Authentication

· Usage plans

· Development stages

· API versioning

· Handle multiple environments (dev, uat, prod)

· Request throttling

· Rate limiting

· caching

There are three ways to deploy API Gateway (endpoint types).

1. Edge Optimized (default) — This is for global clients. API Gateway can be accessed from anywhere in the world.

2. Regional — This is when we expect all our users to be within the same region.

3. Private API Gateway — API Gateway can only be accessed from within VPC.

Resources

https://aws.amazon.com/serverless/

--

--

Rukmal Senavirathne

Graduated from the Department of Computer Science and Engineering at the University of Moratuwa.