1
00:00:00,360 --> 00:00:07,380
In this video, we are going to learn how to invoke a lambda function with passing event JSON object

2
00:00:07,380 --> 00:00:09,440
file using the SLA.

3
00:00:10,020 --> 00:00:11,580
So let's get started.

4
00:00:11,700 --> 00:00:15,860
Please open the Visual Studio code and create an Excel folder.

5
00:00:15,870 --> 00:00:20,160
Which name is lecture 4 to 4 and add the command text file.

6
00:00:20,190 --> 00:00:25,710
So as you can see that before starting a new section, I have created a folder and adding the command

7
00:00:25,710 --> 00:00:29,340
text file and locate command line directory for our lecture.

8
00:00:29,340 --> 00:00:33,600
You can see that command line is indicating section seven, election 44.

9
00:00:34,320 --> 00:00:40,380
So now we can start our lecture as you know, that address Lambda functions invoking with the event

10
00:00:40,380 --> 00:00:41,040
objects.

11
00:00:41,040 --> 00:00:44,160
So events are the field of the lambda functions.

12
00:00:44,310 --> 00:00:51,270
So we can also invoke Edwards lambda function with passing event JSON file is note that in the last

13
00:00:51,270 --> 00:00:53,490
video we put the payload into the our command.

14
00:00:53,490 --> 00:01:02,160
You can see the lecture 43 we put the payload is a JSON format key value payload in the invoke command

15
00:01:02,160 --> 00:01:02,640
line.

16
00:01:02,640 --> 00:01:09,660
But in this lecture we should put to create a man JSON file and pasting JSON file as a payload.

17
00:01:09,720 --> 00:01:16,290
So it is good practice to create a white JSON file in order to store these payload data for that purpose

18
00:01:16,320 --> 00:01:19,530
come to under the lecture port for create new file.

19
00:01:20,900 --> 00:01:21,530
To the.

20
00:01:22,760 --> 00:01:25,520
You want, but JSON file.

21
00:01:25,670 --> 00:01:32,670
And in this file, I'm going to basically create any JSON file, which is the key equals volume.

22
00:01:32,690 --> 00:01:41,000
So this very basic case file that we store in the event JSON object and now we are going to invoke these

23
00:01:41,000 --> 00:01:43,880
lambda function pasting these events in file.

24
00:01:43,910 --> 00:01:46,160
Please come to the command, Jason.

25
00:01:47,180 --> 00:01:53,060
Text file in this G6 file, we basically create our invoke commands.

26
00:01:53,060 --> 00:01:59,630
So before pasting these commands, let me copy paste from my window.

27
00:02:00,410 --> 00:02:03,110
Here you can find the lambda IMO command.

28
00:02:03,140 --> 00:02:09,320
We are specifying the function name and we should have to give silly binary format which is the base

29
00:02:09,320 --> 00:02:10,400
64.

30
00:02:10,400 --> 00:02:16,330
And the important part is in here payload is equal to addressing the file, which is the event JSON

31
00:02:16,340 --> 00:02:16,850
file.

32
00:02:16,910 --> 00:02:23,240
This is basically looking at one decent file in the same directory and it is return back to response

33
00:02:23,240 --> 00:02:24,890
into the response JSON file.

34
00:02:26,000 --> 00:02:28,910
And of course we should make this multi line character.

35
00:02:28,940 --> 00:02:34,760
If you remember the multi-line characters in Windows, we are using this character for Mac, we are

36
00:02:34,760 --> 00:02:35,920
using this character.

37
00:02:35,930 --> 00:02:43,700
So let me make it for the windows and see how we can invoke these lambda function.

38
00:02:44,710 --> 00:02:47,640
Och, this is the windows a month.

39
00:02:48,280 --> 00:02:54,490
And now I'm going to copy these commands, which is a slammed in work and I'm working these my function

40
00:02:54,490 --> 00:02:58,450
pacing to these parameters and the important parameter is payload.

41
00:02:58,480 --> 00:03:06,100
Let's copy and paste the terminal, which is the the related lecture folder in here.

42
00:03:06,100 --> 00:03:08,530
Just hit the enter and see the response.

43
00:03:08,710 --> 00:03:12,790
See, that response is coming again Subscore 200 successfully.

44
00:03:12,820 --> 00:03:15,880
And also there is the naive file which is the response JSON.

45
00:03:15,880 --> 00:03:20,710
If you click this JSON file, you can see the body is come from the helo from lambda.

46
00:03:20,770 --> 00:03:27,940
So we can also verify lambda execution from cloud, which logs if you come to cloud logs and come here

47
00:03:27,940 --> 00:03:34,900
and see the latest log, we can verify that we have execution and it is returned to our halo from lambda

48
00:03:34,900 --> 00:03:35,980
message in the body.

49
00:03:36,190 --> 00:03:37,390
Okay, very good.

50
00:03:37,390 --> 00:03:43,450
So if you summarize this section, we basically invoke lambda function.

51
00:03:43,450 --> 00:03:49,090
You can see the image on the slide that shows client invoking a lambda function synchronously sending

52
00:03:49,090 --> 00:03:50,290
the event JSON object.

53
00:03:50,320 --> 00:03:57,220
Lambda basically sends the events directly directly to the function and sends the function response

54
00:03:57,220 --> 00:03:58,420
back to the invoker.

55
00:03:58,510 --> 00:04:04,870
The payload is a string that contains event in adjacent format, the name of the file where the administrator

56
00:04:04,870 --> 00:04:09,190
writes and the response from the function is response is JSON.

57
00:04:09,820 --> 00:04:16,210
So if the function returns an object error, the response object or error in JSON format will be displayed

58
00:04:16,210 --> 00:04:18,070
under the response JSON file.

59
00:04:18,280 --> 00:04:24,310
If the function exists without error, the response will be the include service code and the body information.

60
00:04:24,520 --> 00:04:29,830
So the output from the command which is displayed in the terminal, including the information from the

61
00:04:29,830 --> 00:04:32,230
header source code and the response file.

62
00:04:32,230 --> 00:04:37,810
And this is including all details and process events from the output of the CLI commands.

63
00:04:38,020 --> 00:04:43,870
If the LAMBDA was able to run the function, the function such code will be the 200 even if the functions

64
00:04:43,870 --> 00:04:44,950
turn an error.

65
00:04:44,950 --> 00:04:50,500
So we have successfully invoke lambda function with the event JSON object.

66
00:04:50,620 --> 00:04:55,330
And now I would like to show how we can get the log ID regarding this invocation.

67
00:04:57,160 --> 00:05:01,600
So now we will focus on the gate lock ID function.

68
00:05:01,600 --> 00:05:08,620
Using these commands, we can use the SLA to retrieve logs for an invocation using the log type command

69
00:05:08,620 --> 00:05:09,220
option.

70
00:05:09,310 --> 00:05:14,140
For that purpose, please open the pseudocode and come the command line.

71
00:05:14,350 --> 00:05:21,640
So basically we will use the log type command to retrieve invocation details from the logs.

72
00:05:21,640 --> 00:05:29,050
The response contains a log result feed that contains up to four kilobyte of base64 encoded logs from

73
00:05:29,050 --> 00:05:30,160
the invocation.

74
00:05:30,160 --> 00:05:35,770
So let me write down the example of the retrieving log ID for that purpose.

75
00:05:35,770 --> 00:05:43,450
I'm hoping the command text window and we basically get retrieve a log ID from an invocation.

76
00:05:43,450 --> 00:05:52,750
So I'm going to get this command, which is the lambda invoke and function name is my function and now

77
00:05:52,750 --> 00:05:56,590
I'm going to use log type parameter which is the tail.

78
00:05:56,590 --> 00:06:00,220
This will be get the details from the Amazon Cloud Watch logs.

79
00:06:00,220 --> 00:06:06,190
So let's see how we can invoke our function and how we can get response with the logs.

80
00:06:06,220 --> 00:06:12,580
As you can see that this is the log result FT including details in our invocations.

81
00:06:12,580 --> 00:06:14,710
But this is not so readable, right?

82
00:06:14,710 --> 00:06:19,990
With this log result, we can grab these log items from the Amazon Cloud watch logs, but this is not

83
00:06:19,990 --> 00:06:22,240
readable for make it readable.

84
00:06:22,240 --> 00:06:30,040
We should use base 64 utility to decode these logs so we can use basics for utility for decoding these

85
00:06:30,040 --> 00:06:30,580
logs.

86
00:06:30,580 --> 00:06:36,850
The basics for utility is available for only Linux and Macintosh operating systems.

87
00:06:36,850 --> 00:06:40,120
So we should run this command with the basic command line tool.

88
00:06:40,120 --> 00:06:42,760
So for that purpose, I'm going to.

89
00:06:43,810 --> 00:06:46,300
Use a different command.

90
00:06:47,230 --> 00:06:49,150
Let me say that.

91
00:06:50,410 --> 00:06:51,310
Macintosh.

92
00:06:51,310 --> 00:06:52,870
We can use this command.

93
00:06:52,990 --> 00:06:59,530
As you can see that I'm using the base 64 utility to decode this line of log results.

94
00:06:59,560 --> 00:07:03,840
So but this only works from the Linux and the Macintosh computer.

95
00:07:03,850 --> 00:07:07,960
In order to run this command, I'm going to create a command line.

96
00:07:07,960 --> 00:07:12,220
You can click this here and we can create a new git bash.

97
00:07:13,960 --> 00:07:14,890
Okay.

98
00:07:14,920 --> 00:07:18,670
I'm creating a new page and I can locate for the.

99
00:07:20,490 --> 00:07:21,480
Section.

100
00:07:22,820 --> 00:07:24,740
So and.

101
00:07:25,780 --> 00:07:26,590
Lecture.

102
00:07:26,770 --> 00:07:27,760
What for?

103
00:07:27,890 --> 00:07:33,290
Okay, now I'm going to copy this line of codes, commands and paste in here.

104
00:07:33,310 --> 00:07:39,460
Basically, we are placing the function name and outlook type as a tail, and the important part is

105
00:07:39,460 --> 00:07:45,160
query log result and output text is using the base 6 to 4 utility.

106
00:07:45,160 --> 00:07:51,790
So if you hit the enter this time, you can see that we have detailed information about Amazon Cloud

107
00:07:51,790 --> 00:07:52,450
Watch logs.

108
00:07:52,480 --> 00:07:58,810
These logs come from the Amazon cloud which logs this the start execution and and execution and the

109
00:07:58,810 --> 00:08:03,180
report with giving the information duration, billing, duration, memory, size and so on.

110
00:08:03,190 --> 00:08:09,880
This is exactly what I see in the command line logs, Amazon cloud logs.

111
00:08:09,880 --> 00:08:13,690
You can see in here start and end the report execution.

112
00:08:13,690 --> 00:08:20,110
So we basically get these log information using this command which pacing the log type as a tail and

113
00:08:20,110 --> 00:08:26,680
query log result and using the base 64 and this command only work from the Linux and the macOS operating

114
00:08:26,680 --> 00:08:27,010
system.

115
00:08:27,010 --> 00:08:33,340
So that's why I'm creating any base window based command window in the pseudocode.

116
00:08:33,340 --> 00:08:41,170
So yes, as you can see that we have seen that we have successfully invoke our lambda function with

117
00:08:41,170 --> 00:08:48,250
the event JSON object and we also get the log ID and the CD log details with basic support commands.
