1
00:00:00,270 --> 00:00:09,420
In this video we are going to learn a lambda function logging in Node.js example it is lambda automatically

2
00:00:09,420 --> 00:00:14,880
monitors lambda functions on behalf and sends the function matrix to the Amazon cloud.

3
00:00:14,880 --> 00:00:15,420
Watch.

4
00:00:15,510 --> 00:00:21,420
A lambda function comes with the cloud watch logs, log groups and the log stream for each instance

5
00:00:21,420 --> 00:00:24,030
or of our invocations.

6
00:00:24,390 --> 00:00:31,140
Lambda Runtime Environment sent details about each invocation to the log stream and relies logs and

7
00:00:31,140 --> 00:00:33,390
other outputs from our function code.

8
00:00:33,660 --> 00:00:40,920
So in this video we will see how to produce log output from our lambda function code and access logs

9
00:00:40,920 --> 00:00:46,650
using the alias CLI and lambda console and see the cloud watch logs.

10
00:00:46,890 --> 00:00:50,310
So let's create an example step for our case.

11
00:00:50,310 --> 00:00:57,450
So in our case, please open the Visual Studio code and see that we will develop Lambda Function Code

12
00:00:57,450 --> 00:00:59,850
to update with the logging information.

13
00:00:59,880 --> 00:01:04,560
Zip function code update function code weekly and invoke updated function code.

14
00:01:04,620 --> 00:01:09,510
So let's start with the first step, which is the Lambda function code.

15
00:01:09,570 --> 00:01:16,860
As you remember that in the last video we have developed this index file to see context object and use

16
00:01:16,860 --> 00:01:18,840
the console log operation.

17
00:01:18,840 --> 00:01:24,420
So in this video, I'm going to update a bit about this function code.

18
00:01:24,420 --> 00:01:28,020
For example, let's remove this log operation.

19
00:01:28,020 --> 00:01:30,510
You can see that this is the standard log operation.

20
00:01:30,510 --> 00:01:34,590
I'm going to use different type of to log into the lambda function.

21
00:01:34,590 --> 00:01:37,620
So I'm going to remove this line of code and test in here.

22
00:01:37,650 --> 00:01:38,310
Okay.

23
00:01:38,460 --> 00:01:46,260
So basically we have some log types we can use console.log for the standard logs and we can use console

24
00:01:46,470 --> 00:01:48,360
info to produce info log.

25
00:01:48,390 --> 00:01:56,550
We can use console that one method for producing warning logs into our cloud watch events for Node.js

26
00:01:56,550 --> 00:01:57,690
Lambda functions.

27
00:01:57,690 --> 00:01:59,640
So please save this file.

28
00:01:59,640 --> 00:02:05,400
And this is the our updated function code and we will follow these log information to the Amazon cloud

29
00:02:05,580 --> 00:02:06,060
logs.

30
00:02:06,060 --> 00:02:14,070
So I have updated our lambda function and follow the steps that we are going to update function.

31
00:02:14,070 --> 00:02:21,450
So basically I'm going to zip function code copy from Windows one and go to lecture five to file and

32
00:02:21,450 --> 00:02:23,400
create a function zip file.

33
00:02:23,400 --> 00:02:27,270
And the third step is update lambda function code with CLI.

34
00:02:27,270 --> 00:02:33,420
So I'm going to use this command which is the update function code giving the function name as my function

35
00:02:33,420 --> 00:02:38,370
tree and specifying the function zip file hit enter.

36
00:02:38,730 --> 00:02:41,460
And this will be update our function code.

37
00:02:41,460 --> 00:02:48,510
You can verify from the management console and the last step is invoke our object, we can create an

38
00:02:49,170 --> 00:02:49,710
object.

39
00:02:49,710 --> 00:02:55,560
So basically I'm copying from previous lecture and paste in here key value.

40
00:02:55,740 --> 00:02:56,400
Okay.

41
00:02:56,400 --> 00:03:01,780
If you follow our command text, we are going to invoke our function bit using this address.

42
00:03:01,920 --> 00:03:09,150
Lambda invoke command and here is my function name and here is the payload paste in here and hit enter.

43
00:03:09,240 --> 00:03:13,230
This will be invoke our lambda function and see the response.

44
00:03:13,230 --> 00:03:15,590
JSON is created successfully.

45
00:03:15,630 --> 00:03:19,920
Now the important thing is we have created three type of logs in here.

46
00:03:19,920 --> 00:03:23,820
So now let's check these logs from the Amazon cloud logs.

47
00:03:23,820 --> 00:03:27,930
For that purpose I'm going to open our application.

48
00:03:27,930 --> 00:03:33,930
So here you can find the lambda functions and open my function tree.

49
00:03:33,960 --> 00:03:42,900
Go to monitor and open veev logs in the cloud watch logs and here we will see the last log stream and

50
00:03:42,900 --> 00:03:46,050
you can see that we have tree log statement in our function.

51
00:03:46,050 --> 00:03:50,070
This tree offline comes with these lines in the cloud logs.

52
00:03:50,070 --> 00:03:54,180
The first one is the console log, standard log, standard log.

53
00:03:54,180 --> 00:03:58,680
That means it is creating info log and the second one is info log.

54
00:03:58,680 --> 00:04:02,760
We are creating an envelope and the last one is one warning log.

55
00:04:02,760 --> 00:04:06,450
You can see warning log is a log type is a one in here.

56
00:04:06,630 --> 00:04:11,370
So as you can see that we have seen a lambda function logging in logs example.
