What is AWS Lambda ? | How to create a Lambda Function?

What is AWS Lambda ? | How to create a Lambda Function?

AWS Lambda is a Serverless Computing service that is a popular AWS service.  We only need to code the process without thinking about the infra-level changes. Let's see in detail about this service.

What is Serverless Computing?

                In traditional Computing when we want to deploy a web application we need to buy all the requirements for it like the hardware, cabling, cooling, network appliances, etc. In this strategy, we need to know the infrastructure requirements and development needs. This is where serverless computing comes into the picture. What if we can only focus on the development and code of the application rather than wasting time maintaining and handling the servers. You may think this can also be known as cloud computing, but what is the difference between cloud computing and serverless computing?

                In Cloud computing, the resources are provided to the users on pay-as-you-go pricing. Whereas serverless computing is where we only develop the code of the application and all the requirements that the application needs are automatically handled by the service provider. Let's take an example, suppose you have a bakery, and different users order pastries and cakes from different locations.

                Regularly, we need to focus on both developing the cakes and taking care of the delivery, in our serverless computing context, the baker only focuses on the development or cooking, and the delivery is handled by a delivery agent. So We need to write the code of our application, which can be standalone applications or microservices, and the service provider will automatically provide the environment and infrastructure for the code.

What is AWS Lambda?

                Let's consider a use case to understand this, suppose we have a storage place where users come and store their information like images, etc. Now we need to compress the image before storing it. So in this case we can use AWS Lambda functions, which only run when an image is added to the storage. All the environments and resource dependencies for the code to run will be managed by the service provider.

                Lambda Functions are called based on the triggers we set up, in the above case when an object or image is added to storage the function will be triggered. Without adding a trigger it will not work, so don't forget to add one. And the cost of this service is also dependent on the execution time of the code, which is very affordable. This service can be used in different domains like streaming applications, web applications, storage and database updates, IoT devices, and even mobile applications.

Features of AWS Lambda

  • Fault Tolerance will be handled automatically based on the request it gets. As we deploy our application or code across different AZs they are highly available and fault tolerant.
  • In some cases there can be multiple requests coming to the server, then there should be a sufficient amount of instances responding to them. But this is serverless computing, we need not worry about the scaling issues, requests are automatically handled by auto-scaling the instances which respond to the request.
  • We can get fine-grade control over the services which we will be using, and we can optimize our code to the tiniest extent to gain maximum performance and the low cost.
  • We can code in different languages like Python, Java, C#, javascript, etc, and it is also included in the free tier of AWS where can create a free lambda function with up to 1 Million requests.

How to create an AWS Lambda Function?

  • For Getting started with creating a function sign in to your AWS management console. It is recommended to sign in as an IAM user and not as a Root user. And search for AWS lambda in the search bar and head to it.

  • You will be redirected to the Lambda service page, where you can see different options and features in it, and all the running functions will be displayed here.
  • Click on the " Create Function " button to start creating a lambda function, There you can see different configurations, we will be sticking to most of the default values.
    • Different options are shown above. we will be developing a code from scratch so select the first tab, or we can use a predeveloped code, or even browse through the repositories.
  • Give a name to the function and select the types of language you will be using. I will be going with Python 3.9, and the architecture is x86_64 and the rest will be default values.
  • Click on create function after configuring all the settings.
  • You can see an option called " Add trigger" this is a configuration that we need to add in order for our function to run, this can be in different scenarios like when data is added to storage services when data is deleted, etc.

  • You can see the code editor above where we can start writing our code and deploy it in the cloud. The thing to remember here is that lambda functions work on events. so whenever there is an event it will be triggered and the event details are passed as a parameter to the lambda function.
  • After completing the code we can test it with custom events or directly deploy it after adding a trigger.

Post a Comment

Previous Post Next Post