1 00:00:00,350 --> 00:00:02,500 ‫So let's have a look at CloudWatch Logs. 2 00:00:02,500 --> 00:00:04,180 ‫And for this, on the left hand side 3 00:00:04,180 --> 00:00:05,930 ‫let's go into Log groups. 4 00:00:05,930 --> 00:00:06,763 ‫So as you can see 5 00:00:06,763 --> 00:00:09,122 ‫we already have one log group available to us, which is, 6 00:00:09,122 --> 00:00:11,090 ‫AWS lambda, demo-lambda. 7 00:00:11,090 --> 00:00:13,580 ‫Well that's because before we created a lambda function 8 00:00:13,580 --> 00:00:15,970 ‫that we ran and that automatically 9 00:00:15,970 --> 00:00:18,750 ‫created some log into CloudWatch logs. 10 00:00:18,750 --> 00:00:20,200 ‫So if we click on this function, 11 00:00:20,200 --> 00:00:22,610 ‫and this is what it was doing, he was running this code. 12 00:00:22,610 --> 00:00:24,410 ‫And so if we go into CloudWatch logs 13 00:00:25,300 --> 00:00:28,240 ‫and click on this log group, 14 00:00:28,240 --> 00:00:30,500 ‫we can see we have one or more log streams. 15 00:00:30,500 --> 00:00:32,160 ‫So here's my log stream. 16 00:00:32,160 --> 00:00:34,250 ‫And within log stream, as you can see, 17 00:00:34,250 --> 00:00:36,470 ‫this represents all the log lines that were logged by 18 00:00:36,470 --> 00:00:39,570 ‫my lambda function. So we have the request ID, 19 00:00:39,570 --> 00:00:42,410 ‫the loading function. Then we get some values, 20 00:00:42,410 --> 00:00:44,600 ‫so value one... and so on, 21 00:00:44,600 --> 00:00:48,640 ‫then end of the request ID and end of the reports and we can 22 00:00:48,640 --> 00:00:50,040 ‫play with it. So that means that 23 00:00:50,040 --> 00:00:53,730 ‫any log line logged by my lambda is going to appear here. 24 00:00:53,730 --> 00:00:56,400 ‫So for example, I can change my lambda function, 25 00:00:56,400 --> 00:01:00,597 ‫and say, "print an extra log line", 26 00:01:01,460 --> 00:01:04,740 ‫and then we're going to deploy this and then I'm going to 27 00:01:04,740 --> 00:01:05,690 ‫test my changes. 28 00:01:05,690 --> 00:01:09,270 ‫So we're going to test it with this test events and then 29 00:01:09,270 --> 00:01:13,180 ‫create, and then demo events perfect 30 00:01:14,400 --> 00:01:16,210 ‫and create now tests. 31 00:01:16,210 --> 00:01:18,380 ‫So now my function is running. 32 00:01:18,380 --> 00:01:19,330 ‫And so what should happen is that 33 00:01:19,330 --> 00:01:21,270 ‫if we go back into CloudWatch logs, 34 00:01:21,270 --> 00:01:24,300 ‫go to my log groups and then within log group, 35 00:01:24,300 --> 00:01:27,180 ‫we have a new log stream. This log stream right here, 36 00:01:27,180 --> 00:01:30,830 ‫contains the log line and extra log line. Okay. 37 00:01:30,830 --> 00:01:34,040 ‫So this is excellent. And this is good for just monitoring, 38 00:01:34,040 --> 00:01:35,960 ‫obviously information about your lambda functions, 39 00:01:35,960 --> 00:01:38,520 ‫but also what happens if there's an exception. 40 00:01:38,520 --> 00:01:40,440 ‫So in this case, what I'm going to do is 41 00:01:40,440 --> 00:01:42,060 ‫I'm going to put a hash sign 42 00:01:43,690 --> 00:01:45,420 ‫in front of this line to comment it. 43 00:01:45,420 --> 00:01:47,370 ‫And now we're going to remove the hash sign 44 00:01:47,370 --> 00:01:48,720 ‫from the line 13, 45 00:01:48,720 --> 00:01:51,590 ‫to have this raise exception, something went wrong. 46 00:01:51,590 --> 00:01:53,690 ‫We're going to deploy the changes again 47 00:01:53,690 --> 00:01:55,390 ‫and test our function. 48 00:01:55,390 --> 00:01:57,890 ‫So now something went wrong and what's going to happen is 49 00:01:57,890 --> 00:02:00,700 ‫that if I go into my Lambda, 50 00:02:00,700 --> 00:02:04,180 ‫there's a new log stream, click on this log stream. 51 00:02:04,180 --> 00:02:07,030 ‫And in here, I'm able to see that exception right here, 52 00:02:07,030 --> 00:02:10,260 ‫and we can look at why our function went wrong. 53 00:02:10,260 --> 00:02:11,470 ‫So this is very handy. 54 00:02:11,470 --> 00:02:13,920 ‫That means that every time a Lambda function is going to run 55 00:02:13,920 --> 00:02:16,470 ‫the logs are going to appear in CloudWatch logs. 56 00:02:16,470 --> 00:02:18,180 ‫But this is not just true for lambda functions. 57 00:02:18,180 --> 00:02:20,770 ‫Obviously this is true for any kind of logs that you want to 58 00:02:20,770 --> 00:02:22,490 ‫appear in CloudWatch logs. 59 00:02:22,490 --> 00:02:24,710 ‫So CloudWatch logs is very handy because you can 60 00:02:24,710 --> 00:02:26,820 ‫troubleshoot maybe errors in your programs 61 00:02:26,820 --> 00:02:29,410 ‫or applications and so on by just looking at the log lines, 62 00:02:29,410 --> 00:02:30,970 ‫within your log groups, 63 00:02:30,970 --> 00:02:33,650 ‫for your services or for your applications directly within 64 00:02:33,650 --> 00:02:34,910 ‫CloudWatch Logs. 65 00:02:34,910 --> 00:02:37,410 ‫And then you can do some login analytics, similar things, 66 00:02:37,410 --> 00:02:39,700 ‫some monitoring and so on. Okay. 67 00:02:39,700 --> 00:02:42,160 ‫And this is super cool again, 68 00:02:42,160 --> 00:02:45,850 ‫and something to definitely go deeper into when you are a 69 00:02:45,850 --> 00:02:48,670 ‫DevOps in a company. So that's it for this lecture. 70 00:02:48,670 --> 00:02:51,670 ‫I hope you liked it. And I will see you in the next lecture.