AWS Lambda – Serverless Computing 

AWS Lambda – Serverless Computing 

We know that AWS provides numerous services to ease developer’s work. These services enable them to focus on their application development (Business logic) instead of focusing on maintaining the underlying infrastructure. 

AWS offers different services for different use-cases. For example, if we are hosting a website, we can use AWS EC2 instances or AWS S3 (if all we need is a static website). However, sometimes we have requirements where our code or application is only called or executed at certain times and then remains idle otherwise. If we choose EC2 for that kind of requirement, it will not be efficient. For requirements like this, AWS provides a service called AWS Lambda. 

OVERVIEW: 

AWS Lambda is a serverless, event-driven compute service that lets you run code for virtually  

any type of application or backend service without provisioning or managing servers. You can  

trigger Lambdas from over 200 AWS services and SaaS (Software as a Service) applications. It can run in response to many kinds of events including changes in state or an update, such as a user placing an item in a shopping cart on an ecommerce website. 

You can use AWS Lambda to extend other AWS services with custom logic or create your own backend services that operate at AWS scale. This means they will have better performance and will benefit from AWS security, among other things. AWS Lambdas automatically run code in response to multiple events, such as HTTP requests via Amazon API Gateway, modifications to objects in Amazon Simple Storage Service (Amazon S3) buckets, table updates in Amazon DynamoDB, and state transitions in AWS Step Functions. 

Lambdas run your code on a highly available compute infrastructure and performs all the  

administration of your resources. This includes server and operating system maintenance, capacity provisioning and automatic scaling, code and security patch deployment, 

and code monitoring and logging. All you need to do is supply your business logic code. 

BENEFITS: 

  • You only pay for the time your code is executed. 
  • You don’t need to manage the underlying infrastructure. 
  • It supports a good amount of programming languages (Python, Java, Node.js, etc..) 
  • It is perfect for event driven applications. 

KEY-FEATURES: 

  • Integrate Lambda with your favorite operational tools 
  • Integrated security model 
  • Connect to shared file systems 
  • Automatic scaling 
  • Connect to relational databases 
  • Package and deploy functions as container images 
  • Built-in fault tolerance 
  • Bring your own code 

EXAMPLE:  

To better understand the working flow of an AWS Lambda we are going to write a hello-world  

program for our lambda and test the same. 

  1. Log in to your AWS account (You can also create one if you don’t already have one, it is free for limited usage) and search for the Lambda in the services search. 
  1. In the Lambda console you can create functions and manage them also. 
  • Click on the create function button. 
  • In the Filter box, enter hello-world-python and select the hello-world-python blueprint. 
  • Then choose Configure. 
  1. You must enter the basic details in the process of creating a lambda. 
  • Name: You can name your Lambda function here. For this tutorial, enter hello-world-python. 
  • Role: You will create an IAM role (referred to as the execution role) with the necessary permissions that AWS Lambda can assume to invoke your Lambda function on your behalf. Select “Create a new role from the AWS policy templates”. 
  • Role name: type lambda_basic_execution. 
  1. Runtime: Currently, you can author your Lambda function code in Java, Node.js, C#, Go, or Python. For this tutorial, use Python 3.7 as the runtime. 
  1. Handler: You can specify a handler (a method/function in your code) where AWS Lambda can begin executing your code. AWS Lambda provides event data as input to this handler, which processes the event. 
  1. Now you can invoke the lambda function you just created and test it. 
  • Select Configure Test Event from the drop-down menu called Test. 
  1. Configure the test event with below values. 
  • Select “Create new event”. 
  • Type in an event name like HelloWorldEvent. 
  • Retain default setting of Private for Event sharing settings. 
  • Choose hello-world from the template list. 
  • You can change the values in the sample JSON, but don’t change the event structure. For this tutorial, replace value1 with “hello, world!”. 
  1. Now test this lambda by clicking on the Test button 

            Upon successful execution, view the results in the console: 

  • The Execution results tab verifies that the execution succeeded. 
  • The Function Logs section will show the logs generated by the Lambda function execution as well as key information reported in the Log output. 
  1.   
  1.  As you can see, our lambda function is working as expected. 
  1. Now we can delete this lambda function as we created this function for this example only 
  1. While you will not get charged for keeping your Lambda function, you can easily delete it from the AWS Lambda console.   

                   a.  Select the Actions button and select Delete function. 

Lambda automatically scales your applications by running your code in response to each trigger, scaling precisely with the size of your workloads. 

Author
Latest Blogs

SEND US YOUR RESUME

Apply Now