Okay, once you are ready, log on to AWS console. And we'll look for lambda services this time. So type lambda, it takes you to the lambda homepage. A couple of things. If you haven't created any lambda functions yet you will see this screen and if you have two lambda functions, then you will see a list of lambda functions on the screen. Now, of course, when you can create lambda functions by couple of ways, either you can create from scratch, you can use some sort of template predefined templates.
Or you can use some repository where you can check in check out and you can create your lambda functions, predefined functions, they are predefined functions and if you want to reuse those functions, then you can reuse those functions and then the lambda will create in this lecture, we We're going to create a function from scratch, since we are going to create kind of inventory application. So let's probably write the function which adds an inventory in the inventory table that we had created in our lecture with Dynamo dB. Now, what we are going to do is we are going to choose no GS eight point or as our runtime because constant functions, they need to know what runtime they need be executing. Now permission thing you every resource in lamda or our artists or just everything in AWS runs on runs with a permission and I am permission if you have an existing role, you can choose an existing role.
What we are going to choose we are going to create a new role. And you can actually define different things roles here what what sort of role a lambda would require to run its function. But of course, it actually needs to have a kind of proper permission to run your lambda functions and underlying the sources written inside the lambda function itself. So, what we are going to create a new role with basic lambda permission, and that what what it what it does is that it is going to create a basic lambda permission. When we have created this lambda functions. It takes some time to create a function.
And if you see it has, it has created a role add inventory code and some sort of snippet here. You can go to Im and verify this particular permission. Now when this screen is loaded, you'll see no J's functionality or a snippet. whether you'd say export dot handler is a kind of handlers for exports, if you have you know done programming in JavaScript or node j s, you might know about exports and how does it work. So, exports exposes your functionality and here what and to run and to get the response from lamda there are some specific formats that you need to add here. So, this is the so these are the facilities what we are running here.
So a couple of snippets const response request response couple of things here you can set environment variables. So if you have experience writing Node JS applications, you might be knowing environment variables here the existing role, basic settings we can set memory starts with 128 Mb and can go up to 3000 Mb is three GB you can actually allocate timeout set to three seconds, three, three minutes, three seconds initially. And then you can define your own timeout period, you can use virtual private network that we're not going to cover in this tutorial. You can set concurrency and other things. So these are all configuration things you can configure. And this is the code snippet what we are running here.
Now, when you have created this function, and if you want to test it, there is a little bit functionality you can test so let's choose HelloWorld event template that that doesn't harm just just right just give an even name, just just give an even name. So, function can you know be different so function can choose this event to be you know, kind of wrong. And then since we are not passing in any parameters, so just leave it blank. In the next lecture, we'll probably come back and revisit this. But now you are ready to run and when you run you will see Hello from lambda response coming up coming out from this lambda functions function you have just written. So it's quite cool, right?
So you don't have an infrastructure you don't own any infrastructure you have written to some no just a script and it runs somewhere it is running. So, what what happens in the background is that there is as we discussed in the last slide, that it it actually creates container on fly runs that Node JS 8.10 environment dead runtime there and it actually, you know, runs that function there. And if you have some sort of some sort of Dynamo DB connection or something then it goes to Dynamo DB It reads writes or you know performs any sort of operations that you have defined in this lambda. Now, what we are going to do we are we are just going to modify the masses a bit So, let's see what is coming What is coming out from those you know, event. So, if you see Hello from event an event key one value one key two relative and key three value three what we have defined when we had in our in our test setup, so, those those those parameters we had defined while we configured our event to run on.
And then it actually gives us in the same way you can actually grab all your body request body when you want to grab your request body you it actually comes to an event. And of course event an event actually considers every you know us Request body it has got and then it actually displays all the other information from this JSON. So, yeah, if you see just everything what we have been discussing so far or what we have discussed so far is all about JavaScript Object Notation JSON object. And on the base of JSON object objects we are creating are several lists in our application in this course, of course, you need to be really mindful of your JSON format. And it actually gives you so we have so what what we are trying to establish what what sort of data we want to add into our dynamodb database and see, we have got ID, we have got name we have got is in stock, we have got total and stuff.
So on the base of these JSON objects, we are going to build our inventory app So this is all about the basic functionality of lambda. And I'll see you in the next lecture.