We have to specify function names while creating them. However, there is a special class of functions for which we do not need to specify function names.
A lambda is an anonymous function that returns some form of data.
Lambdas are defined using the lambda keyword. Since they return data, it is a good practice to assign them to a variable.
The following syntax is used for creating lambdas:
In the structure above, the parameters are optional.
Let’s try creating a few simple lambdas.
Below, we can find a lambda that triples the value of the parameter and returns this new value:
The evolution or timeline of Lambda looks something like this:
On-Prem DataCenter –> IAAS –> PaaS –> containerization/Docker –> Serverless
Lambda is a compute service where you can upload your code and create a Lambda function. AWS Lambda takes care of provisioning and managing the servers that you use to run the code. You do not have to worry about operating systems, patching, scaling etc.
It is essentially described as an event-driven compute service where AWS Lambda runs your code in response to events. These events could be changes to the data in an Amazon S3 bucket or an Amazon Dynamo DB table.
Lambda events can trigger other Lambda events or call other AWS services like SQS or SNS.
Lambda lets you upload a function onto AWS and you pay every time the function is executed or called. You do not need to think about managing the OS or the VM. Lambda does it all for you.
For example, think about a tax calculator. In the traditional model, you would write the code. Procure a virtual machine to deploy your code to the VM. Then you need to maintain, manage your deployment. However, with Lambda you don’t need to pay or manage the VM, Amazon does this for you.