Let’s start with AWS Lambda

What is Lambda

We all know that the almost everything in the internet works by making a request to the some server and we would received a response, either in the form of a page, data in JSON, or any form of stream.

So, if we break down the action done in whole lot of sequence, we will notice that the most smallest action is to send a ‘request’ and that we will get a response from the server. The request itself is usually completes an action either providing the data or making changes to a state of some system, and this action usually encapsulated into a function. And this function is what so called Lambda.

AWS Lambda

Lambda in AWS – Run Code without thinking about Servers

As shown in the screenshot here AWS’s Lambda is a solution that intended for the developer to run code without thinking about server, which means that we can focus more on writing the code and we can ‘forget’ about the server that needs to be managed, hence it is termed as ‘Serverless’.

Let’s make a call to function

To see how lambda in action, we can start with a very simple call, eg. responding to a web request and render a page, which in this case there’s already a base template on accomplishing this.

Creating AWS Lambda

We start with clikcing the Create Function, which we would get a few list of option whether we are going to create from scratch or use a blueprint, in this case since we are making a simple call we will use a blueprint option, especially Getting Started with Lambda HTTP part

Create Function initial window

And in the next page, we would see a list of option that we need to set, we can separate the section to Basic which include basic information like the function name, execution role.
Function URL which contain an acknowledgement for allowing the function to be called publicly, that may incur any cost. And the Lambda function code which contain initial lambda function code, which in this case the template would include an index html file and will be called by the lambda function.

Once ready, we can continue to click the Create Function button and we would be directed to a lambda page properties

My First Lambda properties

And when we have this at the initial point we should be ready to call the page by clicking Function URL which should direct us to the page of “Hello from AWS Lambda”

How it works

With that, we have created our first lambda function from the blueprint and it allows us to open a page from the loaded file of index.html, we know this by looking at the Code Source of the section of the Lambda properties.

we can see that the used code here is based on the Node.js which we can identify from the runtime settings under the code source section.

And if we look at the Handler information we can see the description that the value called is the index.handler which in this case it would call the exports.handler in the index.js, thus we are not directly loading the index.HTML page.

Let see if we can tinker with the loaded file, first let’s make a duplicate of the index.html page and remove some part of the content, to make it different.

Duplicate and modify

And also let’s modify the index.js to load the duplicated index file

modified index file

Once done, let’s Deploy and check the page

And voila, the modified page is shown.

Summary

This is how a simple lambda function is created, and how it is being called directly from the Function URL. Although the power of lambda itself is not only provide a simple HTML call, but it can be triggered by other factor, this can be seen from the Function overview section. Where it is also allowed to be triggered by external event.

With that in mind, perhaps we can explore more on the trigger, and one interresting part that we might be able to use is the API Gateway. But that’s would be another story.