What is the Lambda Service of AWS and how to use it?

AWS Lambda is a computing service that allows you to execute programming without the requirement or maintenance of servers. AWS Lambda only executes the code when it’s needed and instantly scales from a few requests a day to thousands a second. You only pay for the time you consume in the computation-there is no charge if your code is not running. You can use AWS Lambda to run your code in reaction to events such as data changes in an Amazon S3 bucket or an Amazon DynamoDB table; execute your code in response to HTTP requests using Amazon API Gateway, or use API calls made using AWS SDKs to invoke your code.

Overview of all the settings available in lambda functions:

So let’s get started with the Implementation of Lambda Function, and how to create lambda function in AWS.

Step 1: Log in to the AWS console as shown in the previous blog and select the Lambda option from the compute service.

Step 2: After that click on the create function button as marked in the below image.

Step 3: select the author form scratch option and fill the basic details downside as shown in the below image.

Step 4: give any name to your lambda function and choose the runtime language (we have chosen python 3.8)and then choose the role for execution(we already created a role using IAM role service this we will teach you in the later blog that how to create IAM role, for now, you can skip this choosing execution role)and after that click on the create function button as shown in the below image.

Note: In this blog, we are not using the IAM role as we are not using other services here, so you can use the basic IAM role in the later blog we will tell you how to create and use these IAM roles and how to connect with the other services using IAM role.

Step 5: You can see in the below image marked message that our function is created, now we will tell you how to add a trigger to a lambda function, just click on the add trigger button.

Step 6: Select the service on which you want your Lambda function to trigger, as we have selected S3 bucket because we already create one sample S3 bucket for this lambda function(how to create S3 bucket is already explained in the previous blog)

Note: This is just an example of how to add a trigger to your lambda function, the real usage of trigger we will tell you in the later blog.

Step 7: After that give your bucket name and leave all the information as it is as shown in the below image.

Step 8: Then click on the add button to add the trigger for your lambda function.

Step 9: now you can see in the below image your S3 bucket is added as a trigger for your lambda function. after that click on the name of your lambda function as marked below.

Step 10: Write some sample code as shown in the below image.

Step 11: After that click on the save button as shown in the below image.

Step 12: when your code will be saved click on the test button as marked in the below image. (this step is to watch the cloud watch)

\

Step 13: Give your event name as we have given event1 and leave the other things as it is, and click on the test button downside.

Step 14: After that again click on the test button as shown in the below image.

Step 15: you can see the message that there is no error in our code and code execution is succeeded.

Step 16: After that click on the monitoring button as shown in the below image to open the cloud watch window.

Step 17: when your loading will finish you will see this view logs in the cloud watch button on your screen, just click on that button.

Step 18: there is only one log stream because we clicked on the test button just once, now click on the marked log stream in the below image.

Step 19: Now you can see the logs like start request end request etc. in your cloud watch for your lambda function.

Congratulations, you successfully learned how to create lambda function and how to use it now try it by yourself and explore it.

Happy coding!!!!

We make your business smarter and broader through the power of the internet. Researcher | Web developer | Internet of things | AI | www.wakeupcoders.com