Outreachy internship with Mozilla: First lambda function

Hi there!

In this blog post, I will be talking about generating AWS lambda functions. Let’s go ahead. :)

First things first- You should have an Amazon Web Services account. I got mine through Mozilla dev account. Awesome! :D

So, here I am logged into my AWS console. It looks like this-

As we have already seen in my last blog post that AWS Lamda is a part of compute domain. You can certainly see “Lambda” under “Compute” heading in the above image. Now, click on “Lambda” to create a new lambda function. As an example, I will be writing a function to calculate volume of cone in NodeJs.

Now you can create a function code all by yourself or you can use some of the blueprints that amazon gives you. In the image below, you will see a number of blue prints ( some basic codes that amazon gives you).

In order to create a new lambda function, you should provide a name, choose a role ( if you don’t have any previous created role then create a new role and provide a role name to it), runtime etc.

Now, let’s talk about how a basic AWS lambda function looks like. AWS Lambda invokes your Lambda function via a handler object. A handler represents the name of your Lambda function. For example-

Here, in order to invoke our function, we should write the name of the file along with the name of the function in Handler section ( as you can see in above image i.e index.handler). Now, let’s take a look on parameters of the function. Here you can see three parameters- event, context and callback. Callback is something that is used when you want to return something back to the user. The general syntax is- Callback(error, success). Here success can be a string message or the object you want to return. I will talk about event and context in my next blog(API Gateway).

In AWS, each lambda function is executed in a container and you can explicitly specify the memory, time etc settings of each container as shown below-

Once you are done with writing function, you can create a lambda function by clicking on “create button”. After that you can see a success message on your console- “Congratulations! your lambda function ‘xyz’ has been created successfully”. After that you can test your code and the test results would be somelike like this-

Here you can see the response object, response ID, execution time, memory size etc. Well, this is the basic example of generating lambda functions. A lot more things like including triggers etc will be discussed in my next blog ( API gateway). So, stay tuned. :)

Thanks for reading!