Serverless Computing
Tags: serverless, aws, cloud
Published: 2021-07-17 16:53:30

### What is Serverless?
The concept of cloud is to move the infrastructure our application is managed by the cloud vendor. Serverless takes it one step further. With serverless you don't have to worry about anything except for your code. Everything else like the OS of the server, or even the framework of the application is taken care by the cloud vendor. This allows the developer to concentrate only on the code. With serverless, the developer has to write a function that gets executed by a trigger. The trigger is an event that can be configured as per the requirements. Since serverless is mostly functions that respond to triggers, its also called _serverless functions_. Even though it's named serverless, it doesn't really mean that we don't have any servers, it just means we don't have to worry about managing the servers.

### Why select serverless?
Now you might be wondering, why do we need a serverless function? The advantage of a server less function is that you will only be charged for the amount of time your function is hit. You don't need to pay anything if your serverless function is not being used. The others advantage is that you can easily scale up and scale down your function based on its load easily. 

### Popular Serverless Offerings
Serverless functions can be used in lots of scenarios. Because of this, most popular cloud vendors are offering serverless functions. AWS lamda is the first and probably the most popular serverless functions offering. The other famous function offerings are

- Google Cloud Functions from Google Cloud platform
- Azure Functions from Microsoft Azure
- Oracle Cloud Fn from Oracle
- OpenWhisk from IBM


### Working with AWS Lamda.

AWS lamda is the serverless offering provided by amazon web service. Aws provides 1 million requests for free forever which is a great offering. But please note that AWS lamda needs to be called by an another AWS service which might not be free, so please do check AWS pricing for that.
 
We will see a sample AWS lamda funtion created using node js. You can create an AWS lamda function from the AWS console. When you create a new function you will see something like this
![aws lamda](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dxmhmdyv2wnn879a42q3.PNG)

AWS lamda function is called by a trigger. This trigger is by one of the other services offered by the AWS, it can either be a api gateway, S3 bucket, dynamo DB etc.

The function may or may not call other AWS services like S3, or SNS service which will be the destination if it does calls them.

A simple lamda function looks like below in node js.
```
exports.handler = async (event) => {
    const response = {
        statusCode: 200,
        body: JSON.stringify('Hello from Lambda!'),
    };
    return response;
};
```

Every lamda function will have a handler function. The handler is the function that gets called by the trigger. You can write whole application in this handler function like call a DB and send mail etc. AWS makes it very easy to integrate with other AWS services.

Thats it for today. This was a very basic introduction for serverless computing. Please let me know your thoughts in the comments.