AWS Lambda - Introduction (Bring your own code)
AWS Lambda is a serverless computing service provided by Amazon Web Services (AWS) that allows developers to run code in response to events without needing to manage servers. It is a Serverless Compute Service, where you bring your own code and run them without provisioning servers. With AWS Lambda, you can run programs for virtually any type of application or backend services without having to worry about provisioning, maintaining or waiting for service to be built.
Some of the advantages are.
- It automatically scales depending on the amount of user traffic you have, all way up to thousands of executions running at the same time, or all way down to zero and you only have to pay for what you use.
- Easily monitor code performance in real time through CloudWatch.
- Supports programs written in the most popular language used today.
- It also has AP extensions that allows you to use other programming languages not listed. COBOL is one such extension.
How does it work?
- Lambda starts with an event. The event triggers Lambda to do something. The source can be any AWS or custom service that triggers our Lambda.
- Lambda supports both push and pull models for invoking our code.
- In push model, the source directly triggers Lambda and tells it to invoke the code when something happens.
- In the pull model, it pulls data from (DynamoDB Streams or Kinesis Streams) where data is flowing through the stream, or from (SQS) where something is put in a queue and then triggers the code when something happened.
Let's see how we can create a Lambda function using the Lambda console.
- Login to your AWS account
- Go and type AWS Lambda in the AWS Management console.
- Click on Create a Function
You will see a setup page, in which you have 3 options to create your lambda function, for our examples, let's use Author from scratch option. Then enter the name of the function, let's name it myTestHelloWorld. For the runtime click on the drop down, you will see the list of runtime options which was supported, for our example, let's choose Python.
Then click on the Info link next to the Permissions, it will expand and shows the below options.
For our example, let's choose the default option, "Create a new role with basic Lambda permissions", then click on the Create function button. This will take you to the configuration screen
Scroll down to the code tab, you will see the default code provided by Lambda. For example, let's use the default code. Just do a empty edit on the source code, which will enable the Deploy button option, now click on the Deploy button, which will deploy the function. (There is no need of this, if you are using the code as it is, just for testing purpose we are doing this)
Then click on Test Tab, it will show the below screen.
Now provide the name for the test and save it, now click on the Test button, it will trigger the test and show the Execution result on the top o
If you expand the Details option, it will provide you the summary of the execution, like amount of memory that was used, duration it ran, what the billing duration would be and other details.
Now go back to your Code Tab, and click on the Execution result, we can see the returned response successful.
That's all, you've created and executed your first Lambda function successfully.
Happy Programming...!!!
Comments
Post a Comment