AWS Lambda

Description:           

            AWS Lambda is a serverless compute service that runs your code in response to events and automatically manages the underlying compute resources for you. You can use AWS Lambda to extend other AWS services with custom logic or create your back-end services that operate at AWS scale, performance, and security.

Getting Started

  • It is a Compute Service
  • Run your code without Managing servers
  • Server and operating system maintenance, capacity provisioning, and automatic scaling, code monitoring, and logging will be handled by AWS Lambda on behalf of yourself.
  • Scales automatically, from a few requests per day to thousands per second
  • You pay only for the compute time you consume
  • You are responsible only for your code
  • All you need to do is supply your code in one of the languages that AWS Lambda supports (currently Node.js, Java, C#, Go and Python)
  •  Your code will be executed in response to the events such as
    • Changes to data in an Amazon S3 bucket or an Amazon DynamoDB table.
    • HTTP requests using Amazon API Gateway;
    • Invoke your code using API calls made using AWS SDKs
  • Your code will be available in Lambda Functions
  • You can use the AWS Lambda console, AWS CLI, and AWS SDKs to create a Lambda function.
  •  Following steps make you to understand the Lambda function which generates a Random

number between two given numbers using the Nodes.js

 

Steps

 

Step 1: Log In with AWS Console

 

Step 2: Go to Compute section and click on Lambda(Run Code in Response to

Events)

Step 3: New Web page will be opened and click on Get Started Now to create

New Function

Step 4: New Web page will be opened which Number has of Blue

Prints(Sample Codes) such as

    • https-request,
    • hello-world,
    • Cloudwatch-logs-process-data etc

Step 5 : Select a run time as Node.js 4.3

Step 6: Select hello-world(A Starter AWS Lambda function)

Step 7: New Web page will be opened, which has Configure trigger details but

we are not going to do anything will Trigger for this blog so that we will skip this

step, Click on Next.

Step 8: New web page will be opened which has Configure Function details

Step 9: Input the Function Name as ‘random-number-generator’ and leave the Description as it is.

Step 10: Select Runtime as Node.js 4.3

Step 11: Select Code entry type as one of following option ‘Edit code

Inline’,‘Upload  a .zip file’ and ‘Upload a file from Amazon S3’. I am

selecting ‘Edit code inline’ for this Blog

 

Function using Node.js 4.3

‘use strict’

Console.log(‘Loading function’);

 

Export.handler = (event, context, callback) => {

Let min = 0;

Let max = 10;

Let generatedNumber =  Math.floor(Math.random()*max) + min;

 

Call back(null, generatedNumber);

};

 

Step 12: Need to set the lambda function handler and role, we have to do   the

below things,

    • There will be a handler text field which has a value index. Handler, it populates automatically
    • select a role from the following roles Choose an existing role, creating a new role from templates, and Create a custom role. In this blog I am selecting creating new      role from templates
    • Enter Role Name as ‘basic-lambda-execute-role’
    • Enter Policy templates as ‘Simple Microservice permission.’

Step 13: We have to do the below Advanced Settings

 

 

    • Set Memory as 128 MB which is default value but this is a very basic function, so 128 MB is more than enough
    • Set time out as 3 Seconds which also default one, if your function hasn’t finish within the time out period then Amazon kills it and shows an error message
    • By default VPC as ‘No VPC’

 

 

Step 14: Click on Next which goes to the New Page which has the following

Review details.

 

    • Name of the Function
    • Description
    • Runtime
    • Handler
    • Role Name
    • Policy Templates
    • Memory
    • Timeout
    • VPC

 

 

Step 15: Click on Create function once the review is completed.

Step 16: New Web page will be available with following details

Code: You can see your code

Configuration: You can see the ‘lambda function handler and role’ and

Advanced Setting details

Triggers: You can see the Trigger details, but no Trigger available for this Blog.

Monitoring: Here you can see Invocations, Duration,

events and Throttles.

Step 17: Click on Test button on the same page, you can see the Execution

                         resultSummary(which has Request id, Duration, Billed Duration,

Resource configured, Max memory used, etc.) and Log output  down the

screen

Summary:

AWS Lambda is a compute service that lets you run code without provisioning or managing servers. AWS Lambda executes your code only when needed and scales automatically, from a few requests per day to thousands per second. You pay only for the compute time you consume – there is no charge when your code is not running.

Queries?

Do drop a note by writing us at doyen.ebiz@gmail.com or use the comment section below to ask your questions.

 

 

 

 

 

 

`

 

 

 

 

Recent Posts