Serverless AWS Function
First: Login to the Lambda Console
Head to your AWS Management Console and locate Lambda below the section of Compute. Then, select it for the sake of opening the Lambda Console.
Second: Selecting your Lambda Blueprint of your Serverless AWS Function
- From the Lambda console, click on the button Create a Function.
Keep in Mind the following:
Using the console you will be able to view this page just in case you don’t already have a Lambda function created before. In case you have previously created a function, you are going to get the Lambda > Functions page. From the list page, select the option Create a function in order to head straight to the Create function page.
- Click on Blueprints.
- Inside the Filter box, enter “hello-world-python” then choose the “hello-world-python” blueprint.
- After that, select Configure.
Third: Configuring and Creating the Lambda Function which is a Serverless AWS Function
- Start off by filling in the Basic Information regarding your Lambda function.
Basic Information:
- Name: Give a unique name for your Lambda function. In this tutorial, you will need to fill in “hello-world-python”.
- Role: Create an IAM role using the needed permissions which may be assumed by the AWS Lambda for the sake of invoking your Lambda function for you. Click on the option of Create new role from template(s).
- Role name: Enter the following name “lambda_basic_execution”.
Lambda Function Code:
- Under this section, you will be able to go over the example code which is written in Python.
- Head straight to the bottom of the page then click on Create Function.
- Runtime options: It is possible for you to write your Lambda function code using either Python, C#, Java, Node.js or Go. In this tutorial, you will leave it as it is on Python 2.7for your runtime.
- Handler options: It is possible for you to set a handler where Lambda may start with the execution of your code. Lambda offers event data to be this handler’s input, that processes the event.
For our example, Lambda can identify this using the code sample then this needs to be previously populated using “lambda_function.lambda_handler”.
- Keep scrolling down for configuring your VPC, timeout and memory settings. In this tutorial, you will not change the default Lambda function configuration values and instead leave them as they are.
Fourth: Invoking your Lambda Function & Verifying your Results for your Serverless AWS Function
Using the console, you will get to see your “hello-world-python” Lambda function. You will be able to test this function, then start verifying its results, and going over the logs.
- Click on Configure Test Event in the drop-down menu named “Select a test event…“.
- The editor will now show for you to fill in an event for the sake of testing your function.
- Select “Hello World” out of the Sample event template list.
- Enter a specific event name such as “HelloWorldEvent”.
- You are capable of altering the values found in the sample JSON, without changing the event’s structure. In this tutorial, you will need to change the “value1” and enter “hello, world!”.
Click on Create.
- Click on Test.
- When execution completes successfully, go and view your results using the console:
- In the Execution results section, you can verify that that your function’s execution was successful.
- In the Summary section, you can see key info reported in the Log output.
- In the Log output section, you can see the logs which the Lambda function execution tends to generate.
Fifth: Monitoring Metrics of your Serverless AWS Function
- Begin with invoking your Lambda function a couple of extra times through continuously clicking on the Test button. By doing so, you will be generating the metrics which may get viewed in later on in the coming step.
- Click on Monitoring for the sake of viewing your results.
- Keep scrolling down for the sake of viewing your Lambda function’s metrics. These metrics get reported through CloudWatch. It will be possible for you to leverage them for setting custom alarms.
Monitoring tab will display the following six CloudWatch metrics:
Invocation count
Invocation duration
Invocation errors
Throttled invocations
Iterator age
DLQ errors
Using AWS Lambda, you are charged according to your usage. Upon reaching the AWS Lambda free tier limit, you will begin getting charged according to the number of requests for every one of your functions which is known as the invocation count, and according to the time of execution of your code which is known as the invocation duration.
Sixth: Deleting your Lambda Serverless AWS Function
Even though in the free tier you are not going to be charged for keeping this Lambda function, you are capable of simply deleting it using the AWS Lambda console.
- Click on the Actions button then select the option Delete Function.
- Now you will need to give confirmation for terminating this function by simply clicking on Delete.
At Last!
After following this tutorial, you will have completed the creation of your very own first serverless AWS Lambda function. This will be the first step you take for comprehending the way to start running applications with no need for provisioning or managing any servers. Lambda is capable of automatically scaling your apps through running code as a response to every single trigger, while scaling with great precision using your workload’s size.