1
00:00:00,210 --> 00:00:04,080
In this video, we are going to create a lambda function.

2
00:00:04,470 --> 00:00:08,790
It is lambda is one competing rather than an imperative model.

3
00:00:08,790 --> 00:00:11,640
So events will compete in response to events.

4
00:00:11,640 --> 00:00:14,910
When the event source happens, it triggers the lambda function.

5
00:00:15,300 --> 00:00:21,000
The event source will be the API gateway in this case, and the source could be the request of End Point,

6
00:00:21,000 --> 00:00:27,690
which will go through later the API gateway and then the execute to incoming event and interacting with

7
00:00:27,690 --> 00:00:30,480
Dynamo DB to perform CRUD operations.

8
00:00:30,750 --> 00:00:34,320
So we create a lambda function for the back end of our API.

9
00:00:34,380 --> 00:00:39,030
This lambda function creates reads, updates and deletes items from dynamic DB.

10
00:00:39,060 --> 00:00:44,340
The function uses events from the API gateway to determine how to interact with the Dynamo DB.

11
00:00:44,550 --> 00:00:52,380
So in order to create lambda function, please open the mission console, go to a lambda and choose

12
00:00:52,380 --> 00:00:54,270
create function button.

13
00:00:54,810 --> 00:00:58,230
After that we will create a function from scratch.

14
00:00:58,320 --> 00:01:03,750
To do that, I'm going to give the name as a function, as a product function, because we are using

15
00:01:03,750 --> 00:01:07,140
the implementing product microservices.

16
00:01:07,140 --> 00:01:14,160
So if you scroll down, the runtime will be Node.js and leave as it is the other complications.

17
00:01:14,160 --> 00:01:21,510
But if you expand the permissions, so under the permissions type this time we will change default execution

18
00:01:21,510 --> 00:01:28,380
role and we can select the create a new role from a policy template.

19
00:01:29,500 --> 00:01:34,300
So let me select this new role with a WS post template.

20
00:01:34,330 --> 00:01:40,120
After that, if you scroll down, it is requiring a role information role name.

21
00:01:40,120 --> 00:01:43,230
So I'm going to provide the role name as a product role.

22
00:01:43,240 --> 00:01:50,230
And for policy templates, we can choose simple Microsoft's permission, because if you expand this

23
00:01:50,230 --> 00:01:55,210
one here, you can see the different policy templates that manage by the yes.

24
00:01:55,210 --> 00:01:58,360
So we are going to select simple Microsoft's permission.

25
00:01:58,360 --> 00:02:01,510
If you select this one, you can see that it is regarding to Dynamo.

26
00:02:01,510 --> 00:02:08,530
DB So that means this policy grants the Lambda function permissions to interact with Dynamo DB in order

27
00:02:08,530 --> 00:02:10,030
to perform perturbations.

28
00:02:10,030 --> 00:02:15,670
If you scroll down, you can see that we have added a simple Microsoft permission to create role name,

29
00:02:15,670 --> 00:02:22,150
which is the product role, and we use a manage policy for simplicity as a best practice.

30
00:02:22,240 --> 00:02:27,940
We should create our own IAM policy to grant the minimum permissions required, but this time it is

31
00:02:27,940 --> 00:02:34,240
good to use managed policy in a yes by the one creating this lambda function.

32
00:02:34,240 --> 00:02:39,670
Because if you look at the architecture lambda function, interact with the Dynamo DB and it is requiring

33
00:02:39,670 --> 00:02:42,190
the permissions and it is managed by the A.

34
00:02:42,580 --> 00:02:42,750
S.

35
00:02:42,760 --> 00:02:48,610
So that's why when we are creating lambda function, we can create a new role with assigning these dynamo

36
00:02:48,610 --> 00:02:51,160
DB policies, performing the cross operations.

37
00:02:51,990 --> 00:02:54,690
Look, let's create a function.

38
00:02:55,590 --> 00:02:58,430
A lambda function is created successfully.

39
00:02:58,440 --> 00:03:01,200
So now I am going to develop our lambda function.

40
00:03:01,200 --> 00:03:07,980
But this time I'm going to copy, paste this function and let me show how we can best please go to the

41
00:03:08,230 --> 00:03:14,850
pseudocode and go to the Section 17 and lecture 143 and open indexes.

42
00:03:15,090 --> 00:03:23,040
Let's right click copy this code and paste into our Lambda Function code.

43
00:03:23,130 --> 00:03:24,780
So click the deploy button.

44
00:03:25,680 --> 00:03:30,450
So please don't consider how we can write this function in this stage, because we will write these

45
00:03:30,450 --> 00:03:33,600
code step by step and be together in the upcoming lectures.

46
00:03:33,600 --> 00:03:38,130
For now, please download and copy from the video resources and paste into here.

47
00:03:38,220 --> 00:03:44,640
So basically if we explain a little bit, so the handle method is the method that will be executed,

48
00:03:44,640 --> 00:03:47,550
the lambda function and the function takes to object.

49
00:03:47,550 --> 00:03:53,460
As you remember that the event object contains all of the data sent from the event source and the context

50
00:03:53,460 --> 00:03:59,400
object provides several methods and properties and we have copied the snippet code and paste into the

51
00:03:59,400 --> 00:04:02,880
indexes by using the event HTTP method.

52
00:04:02,880 --> 00:04:10,290
You can see in here we want that method to differentiate the HTTP request which comes from the API gateway

53
00:04:10,290 --> 00:04:16,350
and we can basically perform, create, update, delete and retrieve operations with dynamic DB using

54
00:04:16,350 --> 00:04:17,940
the SDK package.

55
00:04:18,210 --> 00:04:24,120
And I will explain these codes and develop with the latest libraries in the upcoming videos.

56
00:04:24,120 --> 00:04:30,810
But this time I'm going to copy and paste to accommodate the incoming request from the API gateway and

57
00:04:30,810 --> 00:04:35,700
you can think that we are using the dynamic DB async package to perform CRUD operations.
