1
00:00:00,300 --> 00:00:06,420
In this video we are going to understand how a lambda triggered with event json object.

2
00:00:06,450 --> 00:00:07,590
You can see the image.

3
00:00:07,590 --> 00:00:14,790
We are creating an event and trigger a lambda function code and arrange and develop our function code

4
00:00:15,180 --> 00:00:17,160
with incoming JSON object.

5
00:00:17,340 --> 00:00:18,690
Let's get started.

6
00:00:19,400 --> 00:00:23,300
Please open the A machine console and go to Lambda functions.

7
00:00:23,480 --> 00:00:24,920
Create a function.

8
00:00:24,950 --> 00:00:28,070
We use a lambda function for the backend or API.

9
00:00:28,100 --> 00:00:35,570
For this example, I also and also during the course, I would like to use Node.js versions as a runtime

10
00:00:35,570 --> 00:00:45,110
so the function name will be the new function and runtime should be the Node.js and architecture live

11
00:00:45,110 --> 00:00:49,400
as it is and the permission leave as it is and click the create function.

12
00:00:51,210 --> 00:00:58,020
This is a standard lambda function and this example function returns a 200 response to client and the

13
00:00:58,020 --> 00:01:00,420
text will be the halo from the lambda.

14
00:01:00,930 --> 00:01:05,450
If you scroll down, you can see the code section is the standard lambda function.

15
00:01:05,460 --> 00:01:08,070
It is turning source code and the button information.

16
00:01:08,620 --> 00:01:08,910
Okay.

17
00:01:08,910 --> 00:01:15,060
Before we start, first of all, we should understand how a lambda triggered with the event JSON objects.

18
00:01:15,180 --> 00:01:19,200
So we opened our lambda function and go to the test section.

19
00:01:20,430 --> 00:01:26,640
So if you scroll down under the test, you can see that these are the test events we set that lambda

20
00:01:26,640 --> 00:01:31,180
triggered with events, so we should provide at least one event from anywhere.

21
00:01:31,200 --> 00:01:35,740
So in this test section, we can invoke our function with a test event.

22
00:01:35,760 --> 00:01:42,270
Also, we can choose a template I will show you soon, but let's see this helloworld template.

23
00:01:42,270 --> 00:01:47,430
If you scroll down, you can see the templates by default it's coming the Helloworld template and this

24
00:01:47,430 --> 00:01:52,710
is the Helloworld template event object so we can give the name.

25
00:01:53,480 --> 00:01:55,330
The test you want.

26
00:01:55,340 --> 00:01:56,840
And if you scroll down.

27
00:01:57,640 --> 00:02:01,770
Select the template helloworld and scroll up.

28
00:02:01,780 --> 00:02:08,470
We can see the save button and click the test button, but before click the test button you can check

29
00:02:08,470 --> 00:02:09,520
the event JSON object.

30
00:02:09,520 --> 00:02:14,320
So that means we will send this JSON object to our lambda function.

31
00:02:14,320 --> 00:02:18,940
So let's click the test button and see how we can send these images.

32
00:02:19,930 --> 00:02:20,590
Okay.

33
00:02:20,590 --> 00:02:25,990
So as you can see that the execution result is succeed and if you expand these details, you can see

34
00:02:25,990 --> 00:02:29,830
the source code is 280 is hello from lambda function.

35
00:02:29,830 --> 00:02:34,900
So we can successfully invoke our lambda function but we don't interact with the incoming even JSON

36
00:02:34,900 --> 00:02:35,620
object yet.

37
00:02:35,620 --> 00:02:42,580
So if you look at the our code window, we don't have any interaction with this even JSON object, we

38
00:02:42,580 --> 00:02:44,560
only return this response.

39
00:02:44,560 --> 00:02:51,730
But we should also interact with the event JSON object because now we are know that we are sending this

40
00:02:51,730 --> 00:02:58,090
information about this Helloworld JSON object and we can interact with these attributes, which is the

41
00:02:58,090 --> 00:02:59,350
key 1 to 3.

42
00:02:59,800 --> 00:03:04,780
So let's modify our code with getting and writing events value from the Lambda function.

43
00:03:04,780 --> 00:03:11,200
I'm going to modify our lambda function in the management console, but you can get the quote from the

44
00:03:11,200 --> 00:03:11,860
OR.

45
00:03:12,400 --> 00:03:16,090
We just do code window under lecture 60.

46
00:03:16,120 --> 00:03:20,740
If you go to index JS, you can see that this is the are updated code.

47
00:03:20,740 --> 00:03:24,640
So I would like to also log into incoming event.

48
00:03:24,880 --> 00:03:30,580
So basically in this line of code, we are logging the incoming event JSON object as adjacent structure

49
00:03:30,760 --> 00:03:35,110
and after that we will interact incoming event object attributes.

50
00:03:35,110 --> 00:03:41,410
So event is key 1 to 3 attributes so that we can interact with logging this information.

51
00:03:41,410 --> 00:03:45,550
And after that we have returned the first key of the event JSON object.

52
00:03:45,550 --> 00:03:47,230
So this is our updated code.

53
00:03:47,230 --> 00:03:54,310
So that's why let's copy this in line of the code and code, go back to our dashboard management console

54
00:03:54,490 --> 00:03:59,020
and please remove this line of codes and paste in here.

55
00:03:59,830 --> 00:04:08,260
Of course we should deploy for the deploying our function and now we can test again with this event

56
00:04:08,260 --> 00:04:09,040
object.

57
00:04:09,040 --> 00:04:12,790
We verified that our event will be this way key.

58
00:04:12,790 --> 00:04:14,590
One, two, three and one, two, three.

59
00:04:14,620 --> 00:04:19,960
If I click the test button now, I'm going to interact with the incoming event JSON object and return

60
00:04:19,960 --> 00:04:20,950
back to volume one.

61
00:04:20,950 --> 00:04:24,820
So how we can interact that we can check from the monitoring with this function.

62
00:04:24,820 --> 00:04:29,920
If you go to monitor and we include watch logs, we will see the logs on the cloud watch.

63
00:04:30,220 --> 00:04:37,330
And if you open the latest logs, you can see that the first line of two are logging the incoming event.

64
00:04:37,360 --> 00:04:42,970
This is the incoming event that we verified from the Lambda function and these are the logs that we

65
00:04:42,970 --> 00:04:46,930
are logging in for logs, volume one, volume two and three.

66
00:04:47,080 --> 00:04:50,290
And the last operation is returning to volume one operation.

67
00:04:50,290 --> 00:04:55,810
So we can verify that this is the following the same steps that we develop in our function.

68
00:04:55,810 --> 00:05:03,520
You can see the function code in here and we have verified that we proceed these lines and execute to

69
00:05:03,550 --> 00:05:05,530
logs, right, to logs in this way.

70
00:05:05,740 --> 00:05:06,400
Okay.

71
00:05:06,400 --> 00:05:07,680
We verified that.

72
00:05:07,690 --> 00:05:14,470
Understand that when we send any test or lambda function, we are signing these event JSON objects and

73
00:05:14,470 --> 00:05:21,010
we can interact with evaluation object to reaching these attributes into our code of the lambda function.

74
00:05:21,370 --> 00:05:26,460
So you can see that we have locked every item into event request and return back to volume one.

75
00:05:26,470 --> 00:05:27,370
In the next video.

76
00:05:27,370 --> 00:05:30,100
We will continue to do some advanced event objects.
