10 AWS Lambda Use Cases to Start Your Serverless Journey
Tags: aws, cloud, serverless, cloudskills
Published: 2022-01-24 19:32:00

**Quick Summary** :- Many big companies such as Netflix, Conde Nast and NY Times are migrating their compute services to serverless. But sometimes the cloud architects are confused about the application of serverless technologies such as AWS Lambda and Azure functions. This blog explains 10 AWS Lambda Use Cases to help you get started with serverless. Some of the use cases are Serverless Website | App Authentication | Mass Emailing | Real-time Data Transformation | CRON Jobs | Chatbot | IoT

At the recently held ServerlessConf, ‘A Cloud Guru’ gave proof of serverless promise saying they were never required to change their architecture due to performance reasons. They are running 287 Lambda functions, 19 microservices with 3.68 TB of data at the mere cost of $580 per month. Read that again!

##Why we use AWS Lambda?

The main benefit of AWS Lambda is that it removes the need for the traditional compute services, thus reducing operational costs and complexity. This results in many benefits such as faster development, easier operational management, scaling, and reduction in operational costs.

Moreover if you have frequent changes in memory usage, Lambda takes care of that as well. It has “Pay as you go” model whose billing is based on used memory, number of request and execution duration rounded up to nearest 100 milliseconds. Its huge leap forward in comparison to EC2.

We are well aware of how serverless helps in elevating our focus to more business-critical tasks by empowering developers and offering cost-friendly solutions. However, we have still observed confusion among people who want to get started with serverless adoption but don’t know where, when and how! This blog post is about them.

Let’s start unfolding each of them with practical examples and benefits it brings to the organizations as well as development teams.

##1. Serverless Website Example with AWS Lambda

Maintaining a dedicated server is outdated, in fact, even a virtual server. Not only it’s tiresome but provisioning the instances, updating the OS, etc. takes a lot of time and distracts you from focusing on the core functionalities.

AWS Lambda along with other AWS services can be used to build a powerful website without having to manage a single server or an operating system. For a basic version, we will use AWS API Gateway, DynamoDB, Amazon S3 and Amazon Cognito User Pool.

![serverless website](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/uvxnge6a2ivnjyxkh5qf.png)
The components used here are used for executing the following functionalities:

- JavaScript in the browser exchanges the data from a backend API built through API Gateway and AWS Lambda.
- DynamoDB is a NoSQL database which is used for storing data through API’s Lambda function.
- Amazon S3 is used for hosting the static website content like HTML, media files, CSS, JavaScript which acts as a front end in the user’s browser.
- Amazon Cognito is used for user authentication and management with the help of secured backend API.

##2. Serverless Authentication Example Using AWS Cognito

Whether you’re running New York Times or a personal blog, personalization plays a huge role when you interact with your users. Amazon Cognito when used with AWS Lambda, can empower you to add pre and post-login hooks to execute your custom logic.

After creating an AWS Lambda function, you can trigger it based on various user pool operations such as user sign-up, user confirmation, sign-in, etc. Not only that, you can experiment with your authentication procedure and make it more challenging, migrate the users and send out personalized verification messages, to name a few.


![Serverless Auth](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kztq9irklwfmtbo9s03u.png)

The following are the common triggering sources from where you can hook your Lambda function:

- Sign-up, confirmation and sign-in
- Pre and post authentication
- Custom authentication challenge
- Pre token generation
- Migrate user
- Custom message
Let’s understand how custom message works. Amazon Cognito will trigger your Lambda function before sending an email or phone verification text or multi-factor authentication which allows you to customize the message as per the requirements. The triggering source for the custom message are:

- Confirmation code post-sign-up
- Temporary password for new users
- Resending confirmation code
- Confirmation code to forget password request
- Manual request for new email/phone
- Multi-factor authentication