Run a Serverless code using AWS Lamda Function!

Running basic code on AWS Lambda without provisioning or managing servers.
Priyanka Sharma
Priyanka Sharma

Created: 06/04/2020 12:57 PM - Updated: 06/04/2020 12:57 PM


Introduction

We will learn the basics of running code on AWS Lambda without provisioning or managing servers. We will see how to create a simple Lambda function using the AWS Lambda console.



Note :- In this guide, we will assume that you already have an  configured AWS console.


Step 1: Enter the Lambda Console

  Open the AWS Management Console , Find Lambda under Compute and click to open the AWS Lambda Console.

Step 2: Select a Lambda Blueprint

Blueprints process events from specific event sources, such as Amazon S3, DynamoDB, or a custom application. They provide example codes for minimal processings.

a.  In the AWS Lambda console, select Create a Function.

Note:On the list page, choose Create a function to go to the Create function page.


b.  Select Blueprints.

c.  In the Filter box, type in Hello World  and select the  blueprint.

d.  Then click Configure.

Step 3: Configure and Create Your Lambda Function

A Lambda function consists of code you provide, associated dependencies, and configuration. The configuration information you provide includes the compute resources you want to allocate (for example, memory), execution timeout, and an IAM role that AWS Lambda can assume to execute your Lambda function on your behalf.


a.  Now enter Basic Information about your Lambda function.

Basic Information:
  • Name: You can name your Lambda function here. 
  • Role: You will create an IAM role  with the necessary permissions that AWS Lambda can assume to invoke your Lambda function on your behalf. Select Create new role from template(s).
  • Role name: type lambda_basic_execution
Lambda Function Code:
  •  You can review the example code authored in Python.

b.  Go to the bottom of the page and select Create Function.


c.  Runtime: Currently, you can author your Lambda function code in Java, Node.js, C#, Go or Python.


d.  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.

e.  Scroll down to configure your memory, timeout, and VPC settings.  For this tutorial, leave the default Lambda function configuration values.

Step 4: Invoke Lambda Function 

The console shows the createdLambda function - you can now test the function, verify results, and review the logs.


a.  Select Configure Test Event from the drop-down menu called "Select a test event..."


b.  The editor pops up to enter an event to test your function.  

  • Choose Hello World from the Sample event template list from the Input test event page. 
  • Type in an event name like HelloWorld.
  • You can change the values in the sample JSON, but don’t change the event structure..

Select Create.


c.  Select Test.


d.  Upon successful execution, view the results in the console:

  • The Execution results section verifies that the execution succeeded.
  • The Summary section shows the key information reported in the Log output.
  • The Log output section will show the logs generated by the Lambda function execution.

AWS Lambda automatically monitors Lambda functions and reports metrics through Amazon CloudWatch. To help you monitor your code as it executes, Lambda automatically tracks the number of requests, the latency per request, and the number of requests resulting in an error and publishes the associated metrics. 


a.  Invoke the Lambda function a few more times by repeatedly clicking the Test button.  This will generate the metrics that can be viewed in the next step.

b.  Select Monitoring to view the results.


c.  Scroll down to view the metrics for your Lambda function.  Lambda metrics are reported through Amazon CloudWatch. You can leverage these metrics to set custom alarms. 

Conclusion 


You  have created your first AWS Lambda function. This is the first step in learning how to run applications without needing to manage servers. Lambda automatically scales your applications by running your code in response to each trigger, scaling precisely with the size of your workloads.

Was this article helpful?

0 Out of 0 Marked As Helpfull

Have more questions? Please Contact Us