1
00:00:00,390 --> 00:00:06,720
In this video, we are going to continue to understand how a download integrate with events JSON objects.

2
00:00:06,840 --> 00:00:13,980
So now let me do factor the code and log part of our a lambda function as remember that our code is

3
00:00:13,980 --> 00:00:14,520
in here.

4
00:00:14,520 --> 00:00:18,240
You can see that we are looking at the incoming events in here.

5
00:00:18,240 --> 00:00:21,980
But what if we change this code and what happened after that?

6
00:00:21,990 --> 00:00:27,810
This is important because once you understand how lambda triggered with event object, you will understand

7
00:00:27,810 --> 00:00:34,410
any resources triggered a lambda function and how we can handle that trigger from the lambda function

8
00:00:34,410 --> 00:00:34,920
code.

9
00:00:35,040 --> 00:00:39,210
You can see the image if you understand how events triggered the lambda function.

10
00:00:39,210 --> 00:00:45,180
We can also understand how different services trigger our lambda function with even JSON objects.

11
00:00:45,180 --> 00:00:47,760
So now let's modify our code.

12
00:00:47,760 --> 00:00:51,210
So in order to modify our code, please open the visitor code.

13
00:00:51,210 --> 00:00:56,010
And under the lecture 61 we can see that this is the are updated code.

14
00:00:56,010 --> 00:01:02,490
This time we again log into incoming event and after that this time I'm going to log even the name and

15
00:01:02,490 --> 00:01:05,700
surname and return back the event name and the surname.

16
00:01:05,700 --> 00:01:08,880
So let's modify the code and see what happens.

17
00:01:08,910 --> 00:01:15,720
If you go to the function code and remove this line of codes and paste your copy code and deploy the

18
00:01:15,720 --> 00:01:16,860
lambda function.

19
00:01:17,760 --> 00:01:22,260
Now we are ready for the test, our function with this latest code.

20
00:01:22,290 --> 00:01:26,760
We are basically looking to name and surname and return back the name and surname.

21
00:01:27,120 --> 00:01:33,540
If you go to the test section and scroll down and we will send the same event JSON object.

22
00:01:33,570 --> 00:01:40,210
Let's click the test button and see what's happened with these even JSON object.

23
00:01:40,230 --> 00:01:43,290
So as you can see, that execution result is succeed.

24
00:01:43,290 --> 00:01:46,720
But this time we have seen undefined and undefined.

25
00:01:46,740 --> 00:01:51,030
So if you monitor again with the cloud, which logs see what happened.

26
00:01:52,960 --> 00:02:00,070
Open the Ladies Auxiliary and see that this is the incoming event in our function and we are looking

27
00:02:00,070 --> 00:02:01,000
to name and surname.

28
00:02:01,000 --> 00:02:05,290
But these events Jason object not contains name and surname attribute.

29
00:02:05,290 --> 00:02:09,700
So that's why they are undefined and these are returning the undefined message.

30
00:02:09,700 --> 00:02:14,830
So we should also change these incoming event from our lambda function.

31
00:02:14,830 --> 00:02:18,490
So please go to lambda function and go to test block.

32
00:02:18,490 --> 00:02:22,420
And if you scroll down this time I'm going to create an event.

33
00:02:22,420 --> 00:02:26,500
This event name is name, surname, event.

34
00:02:28,170 --> 00:02:31,300
And if you scroll down, we are going to update these events.

35
00:02:31,350 --> 00:02:34,620
Subject So what will be the subject?

36
00:02:34,620 --> 00:02:40,530
If you open the or use the code and go to event object, you can see that it is basically expecting

37
00:02:40,530 --> 00:02:43,980
to us name and surname attributes in the event JSON object.

38
00:02:43,980 --> 00:02:49,290
So I'm copy this line of code and paste in here or you can write by yourself.

39
00:02:49,290 --> 00:02:54,630
And basically this will be the or any event object for the updated lambda function code.

40
00:02:54,690 --> 00:02:58,440
So let me scroll up and save this event.

41
00:02:59,190 --> 00:03:03,030
And now I'm going to taste this event with clicking this test button.

42
00:03:04,020 --> 00:03:09,960
So if you scroll up and see the details now, you can see the response is a successful becomes what

43
00:03:09,960 --> 00:03:11,190
we have expected.

44
00:03:11,190 --> 00:03:18,450
So if we check the logs again between the cloud logs and open the latest log c three, we can see the

45
00:03:18,450 --> 00:03:20,340
logging to hold event object.

46
00:03:20,340 --> 00:03:23,370
You can see that this time it is not undefined.

47
00:03:23,370 --> 00:03:24,110
Name ma'am.

48
00:03:24,270 --> 00:03:25,530
So name is Oscar.

49
00:03:25,530 --> 00:03:31,560
So it is the best practice to log incoming event JSON object in order to understand which attributes

50
00:03:31,560 --> 00:03:32,730
coming to values.

51
00:03:32,730 --> 00:03:38,250
So that's why the first line of code always we have incoming event logging the incoming event.

52
00:03:38,250 --> 00:03:41,640
So this is the best practice to write this line of code.

53
00:03:41,880 --> 00:03:45,090
Let me show this is very important to understand incoming event.

54
00:03:45,090 --> 00:03:50,430
And after that, with the incoming event, we understand that we should reach even JSON object name

55
00:03:50,430 --> 00:03:55,470
and surname attributes and we perform the logging operation and apply the our business logic.

56
00:03:55,470 --> 00:03:57,870
Return this message to our application.

57
00:03:57,870 --> 00:03:59,340
You can see the execution result.

58
00:03:59,370 --> 00:04:05,220
This is the response and these are the logs in our Amazon cloud, which logs, as you can see, that

59
00:04:05,220 --> 00:04:11,880
we have understood that how it is triggered with event JSON object and in the next video we are going

60
00:04:11,880 --> 00:04:16,370
to develop some hands on log in order to understand lambda events and develop lambda functions.
