Invoking a Serverless “Hello World” Lambda Function

First I will note the benefits of Lambda. Then I will run code without provisioning or managing servers using the Lambda console. Then I’ll manually invoke an event, and finally I’ll review my output metrics.

FYI everything in this exercise is free-tier eligible.

The benefits of Lambda include but aren’t limited to the fact that there are no servers that need managing, Lambda is continuously scalable, it is cost-optimized to the millisecond, and performance is consistent regardless of scale.

First head to the Lambda dashboard (Image 1). Then create a function by clicking “Create function” in the right hand corner.

Image 1

Here we are going to use a blueprint (Image 2), because it already has sample code for us making it easier to quickly launch. Under Blueprints search & select “hello-world-python.” Then click “Configure” in the bottom right of the page.

Image 2

When configuring, keep in mind that you are configuring the compute resources that you want to allocate (ie memory), execution time out, and an IAM Role that Lambda can assume in order to execute functions on your behalf. Image 3 & 4 show my configurations, where I created a role from a policy template, named my function, and ensured the code was completely populated. I then clicked “Create function” at the bottom of the page.

Image 3
Image 4

Image 5 verifies successful creation of the function.

Image 5

In the Lambda Function’s dashboard, I went to Test, named my test event “kevinshelloworldevent”, and changed one of the JSON key values to “Aloha World!” as seen in Image 6.

Image 7

Then in Image 7, I saved changed and clicked “Saved event.” Then I tested the event by clicking “Test.”

Image 7

Image 8 shows a the test occurred with details logged.

Image 8

The above results show that the test succeeded at the top. Also in the Summary section you can see key information. Some of this information is very useful for items such as billing. In this case note I was only billed for a duration of 3 milliseconds.

Then the log output (Image 9) shows the logs generated by executing the function.

Image 9

For more information on your Lambda function metrics, keep in mind that Lambda automatically reports metrics to Cloudwatch.

For the purpose of viewing more metrics, I proceeded to click Test several times. This enabled me to have larger numbers viewable when I went to the Monitor tab in my function (Image 10).

Note this was successful but because it was such a small, brief function I ran only a few times, only some dots are showing up on the graphs rather than the larger lines with higher counts that would appear if this was done with a larger function over a longer period of time.

Image 10

I then proceeded to delete the function (Image 11).

Image 11

For more information on Lambda, please go to AWS’ page dedicated to reviewing Lambda.

Cloud & DevOps. Also Blockchain.