1
00:00:00,300 --> 00:00:07,260
In this video we are going to develop lambda function for incoming HTTP API, even JSON object to perform

2
00:00:07,260 --> 00:00:08,280
CRUD operations.

3
00:00:08,280 --> 00:00:09,540
So let's get started.

4
00:00:09,540 --> 00:00:16,170
We are in this stage, we get this all events JSON from incoming different HTTP methods and now we will

5
00:00:16,170 --> 00:00:21,900
develop these lambda function according to incoming event JSON files to perform CRUD operations.

6
00:00:22,050 --> 00:00:24,840
So to do that, please open the widgets to your code.

7
00:00:24,840 --> 00:00:32,040
And in here, as you can see that we have you won't get even get by ID and event post requests so we

8
00:00:32,040 --> 00:00:37,470
will collect all these incoming event JSON objects that we are going to develop our lambda function.

9
00:00:37,470 --> 00:00:43,620
Now to develop our lambda function, I have created the index space under the lecture folder.

10
00:00:43,620 --> 00:00:47,730
So we basically implement this method in here.

11
00:00:47,850 --> 00:00:50,190
As you can see that this is the dummy method.

12
00:00:50,190 --> 00:00:53,760
Didn't implement any business logic now, but you are.

13
00:00:54,030 --> 00:00:59,910
I would like to explain that this is the method body and in the first line of code we always log the

14
00:00:59,910 --> 00:01:02,040
incoming event to see from the Amazon cloud.

15
00:01:02,190 --> 00:01:05,340
Look, after that I have created a try case below.

16
00:01:05,430 --> 00:01:08,290
So this is also best practice to use this case.

17
00:01:08,370 --> 00:01:16,080
BLOCK When you integrate with the API gateway related services, so basically we will create a body

18
00:01:16,110 --> 00:01:22,440
definition in here and we have created try case look in the trial look, we will implement the actual

19
00:01:22,440 --> 00:01:23,910
business code in here.

20
00:01:23,940 --> 00:01:30,870
And after that we will lock the body and after that we have to return a 200 such code if everything

21
00:01:30,870 --> 00:01:37,050
goes well and the body information and the details should be sent in this line of code.

22
00:01:37,050 --> 00:01:39,180
So this is important to send.

23
00:01:39,210 --> 00:01:44,430
So this code and the body information to response back the client application for the API gateway integrations

24
00:01:44,430 --> 00:01:48,650
with the lambda and if there is any error into this to do.

25
00:01:48,680 --> 00:01:50,040
BLOCK We have a case.

26
00:01:50,040 --> 00:01:50,820
BLOCK In the case.

27
00:01:50,820 --> 00:01:57,900
BLOCK We basically log the error and after that the term back to source code 400 and give the body information

28
00:01:57,900 --> 00:01:59,940
with the message and the error details.

29
00:01:59,940 --> 00:02:07,320
So this is the best practice to make structure your lambda functions according to this three page block.

30
00:02:07,320 --> 00:02:13,410
Now I'm going to intimate this to do part, so let's implement this lambda function.

31
00:02:13,410 --> 00:02:16,560
Basically, we will accommodate the incoming events.

32
00:02:16,560 --> 00:02:19,530
So which events comes to this lambda function?

33
00:02:19,830 --> 00:02:26,580
We will see these events from the event JSON object, for example, the basic get product method comes

34
00:02:26,580 --> 00:02:31,650
with the rock and roll pet and we will look at the rock, right?

35
00:02:31,650 --> 00:02:38,850
So if you look at the get by ID again, we need to get the rock and roll pet to get the rock to understand

36
00:02:38,850 --> 00:02:41,970
the exact URL is matching or not.

37
00:02:42,000 --> 00:02:49,470
After that, if there is additional properties like ID pet parameters, we will check the pet parameters.

38
00:02:49,470 --> 00:02:56,340
And also if you look at the what is then a post request, we will see the body information.

39
00:02:56,340 --> 00:03:03,210
So that means Rod Key is important key attribute to develop our lambda function.

40
00:03:03,210 --> 00:03:06,660
For that purpose, I'm going to write the switch statement.

41
00:03:07,320 --> 00:03:09,840
So the key value for us event.

42
00:03:10,570 --> 00:03:11,230
But.

43
00:03:12,730 --> 00:03:13,180
Key.

44
00:03:13,760 --> 00:03:15,460
So we will check the road key.

45
00:03:15,470 --> 00:03:16,250
So.

46
00:03:17,650 --> 00:03:19,060
If the real key is.

47
00:03:20,220 --> 00:03:21,540
Get product.

48
00:03:24,240 --> 00:03:26,620
Actually, it is good to copy from me in here.

49
00:03:26,640 --> 00:03:28,910
We will check the dot k and E throughout k.

50
00:03:28,920 --> 00:03:32,070
Exact same text with the get product.

51
00:03:32,070 --> 00:03:33,980
So we will implement the get product.

52
00:03:33,990 --> 00:03:41,220
So I'm going to basically set the body information with predefined text for the processing to get all

53
00:03:41,220 --> 00:03:46,560
products, not to integrate dynamic DB for now to implement all these case blocks.

54
00:03:46,560 --> 00:03:52,290
So basically this is the first case and I would like to continue the another case blocks.

55
00:03:52,290 --> 00:03:52,950
Right.

56
00:03:54,680 --> 00:03:57,590
So the second case look is get by ID.

57
00:03:57,620 --> 00:03:59,660
I'm going to copy from here.

58
00:04:00,560 --> 00:04:02,750
And come to court.

59
00:04:02,780 --> 00:04:09,950
So if the key is product ID this time, I have to check the parameters.

60
00:04:09,950 --> 00:04:10,610
Right.

61
00:04:10,610 --> 00:04:16,640
So because Gateway ID is required to get ID information from the PED parameters.

62
00:04:16,640 --> 00:04:22,730
So that's why I have to put one more F in here if you want that.

63
00:04:23,770 --> 00:04:25,270
Pet parameters is not.

64
00:04:25,270 --> 00:04:25,750
Not.

65
00:04:27,310 --> 00:04:29,260
I'm going to copy paste in here.

66
00:04:31,110 --> 00:04:38,160
You can see that you will check the parameters and get the parameters info from these attributes for

67
00:04:38,160 --> 00:04:38,710
that purpose.

68
00:04:38,730 --> 00:04:44,400
I also get this line of code and remove this body.

69
00:04:45,120 --> 00:04:45,750
Okay.

70
00:04:45,780 --> 00:04:47,670
If you look at this line of code.

71
00:04:49,590 --> 00:04:51,270
Let me make it more clear.

72
00:04:52,320 --> 00:04:57,700
This is basically implement to accommodate the incoming demand with get by ID of product.

73
00:04:57,720 --> 00:04:59,590
We will check the road.

74
00:04:59,610 --> 00:04:59,880
Okay.

75
00:04:59,910 --> 00:05:02,520
And after that we will check the is there an iPad parameters?

76
00:05:02,520 --> 00:05:07,980
If there is a parameters, we will implement the actual logic with the ID information.

77
00:05:07,980 --> 00:05:13,950
For now, I'm going to write down the body information with getting event pad parameters that ID volume.

78
00:05:13,980 --> 00:05:20,160
So this part is accommodate the request of the gate product slice one, two, three, four OC.

79
00:05:20,160 --> 00:05:26,400
So now is the same way I'm going to continue with the post and delete operation for that purpose.

80
00:05:27,090 --> 00:05:29,160
Let me remove this line of code.

81
00:05:30,180 --> 00:05:31,440
I'm -- in here.

82
00:05:32,420 --> 00:05:34,520
Yes, you can find that.

83
00:05:41,560 --> 00:05:44,100
You will have switch statement in this way.

84
00:05:44,110 --> 00:05:49,990
So basically after the product and product buy ID, we have implemented the post product.

85
00:05:50,020 --> 00:05:55,690
In this case, if there is a post product, that means we have to get the body information and pass

86
00:05:55,690 --> 00:05:57,920
this body information for that purpose.

87
00:05:57,940 --> 00:06:03,910
We are getting the payload with JSON, that pass method, getting the event body information after we

88
00:06:03,910 --> 00:06:04,810
get the payload.

89
00:06:04,840 --> 00:06:08,190
We basically implement the insert operation to the Dynamo DB.

90
00:06:08,200 --> 00:06:15,490
But now I'm going to use set the text message for the payload to see implement post product.

91
00:06:15,670 --> 00:06:19,090
And the last item is the delete by product.

92
00:06:19,300 --> 00:06:25,690
So it's the same way when I get product ID this time we will delete product by ID.

93
00:06:26,530 --> 00:06:31,450
For that purpose, we will check the parameters and get the parameters into our text message.

94
00:06:31,480 --> 00:06:33,850
You can see these comments in here.

95
00:06:33,850 --> 00:06:39,570
We accommodate the HTTP delete post, get buy ID and get product in this line of code.

96
00:06:39,580 --> 00:06:45,310
So this is the our latest version of the switch statement and we can remove please make sure that your

97
00:06:45,310 --> 00:06:48,000
code also identical with this switch block.

98
00:06:48,040 --> 00:06:53,530
After the switch, look, we basically log the body information and turn back the body information,

99
00:06:53,530 --> 00:06:55,840
which is also code is 200.

100
00:06:55,840 --> 00:06:59,380
And if there is any problem in our business logic, we have a catch.

101
00:06:59,380 --> 00:07:04,180
BLOCK It is turning to 400 and the message error details.

102
00:07:04,210 --> 00:07:06,640
Of course, we will log the error message also.

103
00:07:06,640 --> 00:07:11,020
So this is the latest implementation of our Lambda function.

104
00:07:11,020 --> 00:07:19,300
Basically, we handle all incoming requests from the HTTP API by looking the event that Rod K and according

105
00:07:19,300 --> 00:07:23,770
to the key attributes, we will implement our get post and delete operations.

106
00:07:23,950 --> 00:07:26,140
After that we will perform CRUD operations.

107
00:07:26,140 --> 00:07:31,150
But in order to make simple, I am not calling any database communications for now.

108
00:07:31,180 --> 00:07:36,780
Instead of that, I have set the body information with the required parameter and attribute value.

109
00:07:36,790 --> 00:07:42,670
But of course we will implement and communicate dynamic DB in the upcoming videos with the latest hands

110
00:07:42,670 --> 00:07:43,040
on loop.

111
00:07:43,180 --> 00:07:46,540
But for this example, it is good to stay live as it is.

112
00:07:46,540 --> 00:07:50,010
So now I'm going to deploy this function for that purpose.

113
00:07:50,020 --> 00:07:51,580
Let's copy all.

114
00:07:52,880 --> 00:07:54,330
Copy all quotes.

115
00:07:56,240 --> 00:08:00,860
So after that, go to the lambda function, product function.

116
00:08:01,980 --> 00:08:04,380
And come to the cold part.

117
00:08:05,510 --> 00:08:07,100
Remove and paste in here.

118
00:08:07,310 --> 00:08:10,340
So deploy or code.

119
00:08:11,280 --> 00:08:17,850
As you can see that we have successfully developed our lambda function that can handle all income requests

120
00:08:17,850 --> 00:08:20,310
from the API Gateway HTTP API.

121
00:08:20,340 --> 00:08:24,450
In the next video, we will test our internet operations.
