Lambda is a serverless compute service offering from AWS and it intends to be an eventual replacement for EC2 instances. This allows users to run code without actually provisioning or administering servers.
Lambda comes with the following features:
The user is isolated from all of the compute service management overhead which takes place in the background.
AWS Lambda executes code only when needed and scales automatically.
The user is charged only for the number of requests they execute against lambda and the duration of execution of each request rounded to the nearest 100ms.
Lambda presently support Node.js, Java, C# and python languages.
The code we run or trigger against AWS Lmbda is called a Lmbda function.
To get started select Lambda under compute section of the AWS services view.
Since I don't have any existing lambda functions set up I'll be taken to the getting started page.
Click on get started now.
We'll be brought to the new function configuration wizard. The first steps towards creating a new lambda function is to create a blueprint.
The blueprint is the actual code that we need to run against the lambda platform. AWS makes a number of sample blueprints available for users to play around with.
I'll be using one such sample blueprint which is hello world written in python.
Just type hello in the filter box. The list of available blueprints with that name will appear. Select the one using python 2.7 by clicking on it.
Next we'll be presented with the option of adding triggers. A trigger is basically an event which will launch execution of the lambda function we are writing. This could be an SNS notification, cloudwatch alarm etc. Click next.
Here we have the configure function menu where we will name out function, give a brief description and make changes to the function's code if deemed necessary.
On scrolling down we have the option of creating/providing a role to use with the lambda function. The role here is an IAM role and will have sufficient privileges required for the code to execute in case interaction with our AWS services is involved.
On scrolling down further we can see the amount to of memory to be given to the code when it executes. This is customizable.
In the final section we add network information for the code if we wish for our function to be executed within a VPC. I've tried using a VPC and I couldn't create the function due to privilege errors so I've left this section blank for now.
From here click next. This will create the function and we'll now be taken to the functions section of the AWS lambda service dashboard.
To run the function click on test. We'll be shown the below screen to review the parameters the code will use.
Continue with the execution. This is a one time question. You will not be shown these during future invocations of the lambda function.
As you can observe the function has executed successfully.
As you can notice the 'billed duration' is 100ms meaning that AWS lambda rounds off the code execution billings to the nearest 100ms.
You can click on the monitoring tab to view metrics related to the function. The metircs include number of invocations, duration of code execution etc.
We can click on functions within the lambda dashboard to view the created functions available.
By selecting the lambda function and clicking on actions we can view the available actions for this function.
This was a very basic example of using AWS lambda.
No comments:
Post a Comment