How to create lambda function in AWS?

Reading Time: 3 minutes

Introduction:

In this blog, I will show you how to create lambda function. But first we will see what is lambda function.Lambda is a server light service on AWS where you can only pay for what you are going to use in terms of compute usage and so there is no charge when your code is not running.Lambda function is a small anonymous function. It is a function that take any number of arguments, but can only have one expression. It reduce the number of lines of code when compared to normal python function defined using def keyword.

How to create lambda function:

Step1: First log into the AWS console. Once you navigate to the service, search for lambda and this will open the lambda management console. Here you can see all the existing function listed.

Step 2: Let us create one function. Click on create function. There is two options (i) Author from scratch (ii) blueprints. Blueprints are the pre- configured template.

Step 3: So for now we are going with author from scratch. Here we define the name of lambda function. Lets define it as test and select the runtime i.e python. You can also choose an existing role if you have or you can create one by selecting the create a custom role and it will redirect you to the new webpage. Click on allow and it will create a pre- configured role that is lambda equals to execution.

Here role is already created. So select the choose an existing role that is lambda_basic_execution and click on create function. So it will create the function name test with the ARN. Here is our code paste which is below the function code.

Step4: So you can print the statement and you can save it and test it. While you click on test, it will ask you to define an event. So we will define an event let’s say test and you can see it’s execution result is success. So you can click on return and see your return statement that is Hello which is the return statement and this is the print statement that we have printed i.e. my test lambda function.

Step 5:Apart from that you can go to the report that is duration it is 0.25 milliseconds to build duration is 100 milliseconds. The memory size that we have allocated and the max memory used is 22 MB from 128 MB. This is how we create lambda function.

Conclusion:

 Lambda function is just like any normal python function, except that it has no name when defining it, and it is contained in one line of code. A lambda function evaluates an expression for a given argument.

knoldus

Written by 

I am reliable, hard-working with strong attention to detail and eager to learn about new technologies and business issues. I am able to work well both on my own initiative and as part of a team.