1 00:00:00,210 --> 00:00:02,100 ‫So let's understand a very important concept, 2 00:00:02,100 --> 00:00:02,933 ‫which is event 3 00:00:02,933 --> 00:00:05,610 ‫and the context objects in your Lambda function. 4 00:00:05,610 --> 00:00:07,620 ‫So let's take an example where your Lambda function 5 00:00:07,620 --> 00:00:11,760 ‫is invoked, for example, by a EventBridge rule. 6 00:00:11,760 --> 00:00:12,593 ‫So what's going to happen 7 00:00:12,593 --> 00:00:14,760 ‫is that EventBridge is going to create an event 8 00:00:14,760 --> 00:00:17,790 ‫and that event is going to be passed to your Lambda function 9 00:00:17,790 --> 00:00:20,460 ‫and your Lambda function will receive that event, 10 00:00:20,460 --> 00:00:22,530 ‫and it's called the event object. 11 00:00:22,530 --> 00:00:25,830 ‫And the event object includes a lot of detail around, well, 12 00:00:25,830 --> 00:00:27,360 ‫the event itself. 13 00:00:27,360 --> 00:00:29,070 ‫Where it was emitted from 14 00:00:29,070 --> 00:00:31,410 ‫and the service itself will include a lot 15 00:00:31,410 --> 00:00:34,440 ‫of data related to that event in the event. 16 00:00:34,440 --> 00:00:36,210 ‫But we also have the context object. 17 00:00:36,210 --> 00:00:38,760 ‫So this is the second part of your Lambda function 18 00:00:38,760 --> 00:00:41,370 ‫and this is more some metadata around your function, 19 00:00:41,370 --> 00:00:44,970 ‫such as the request ID from AWS, your function name, 20 00:00:44,970 --> 00:00:47,340 ‫the log group associated with your Lambda function, 21 00:00:47,340 --> 00:00:49,320 ‫the memory limit, and so on. 22 00:00:49,320 --> 00:00:51,570 ‫So this event object and this context object 23 00:00:51,570 --> 00:00:53,880 ‫are very different but very complementary. 24 00:00:53,880 --> 00:00:56,520 ‫So the event object is a JSON-formatted document 25 00:00:56,520 --> 00:00:59,640 ‫that contains data that the function is going to process. 26 00:00:59,640 --> 00:01:01,500 ‫So the invoking service, for example, 27 00:01:01,500 --> 00:01:05,550 ‫EventBridge or SQS or SNS or whatever you want 28 00:01:05,550 --> 00:01:07,920 ‫will contain all the information needed 29 00:01:07,920 --> 00:01:10,770 ‫for your Lambda function to process the events. 30 00:01:10,770 --> 00:01:13,290 ‫Then based on the runtime you're using, 31 00:01:13,290 --> 00:01:16,680 ‫this event object is going to be converted into an object. 32 00:01:16,680 --> 00:01:18,060 ‫For example, if you're using Python, 33 00:01:18,060 --> 00:01:20,550 ‫it's is going to be converted into a dictionary. 34 00:01:20,550 --> 00:01:22,230 ‫So any kind of input, arguments 35 00:01:22,230 --> 00:01:25,050 ‫or invoking service arguments are going to be contained 36 00:01:25,050 --> 00:01:26,790 ‫in the event object. 37 00:01:26,790 --> 00:01:28,860 ‫The context object, on the other hand, 38 00:01:28,860 --> 00:01:31,590 ‫provides methods about the data 39 00:01:31,590 --> 00:01:34,920 ‫of the invocation itself and the runtime environment. 40 00:01:34,920 --> 00:01:37,620 ‫So this is passed to your Lambda function at runtime 41 00:01:37,620 --> 00:01:39,480 ‫and from the context object, 42 00:01:39,480 --> 00:01:43,350 ‫we can get the AWS request ID, the function name, 43 00:01:43,350 --> 00:01:45,870 ‫the memory limit in megabytes and so on, and we can use 44 00:01:45,870 --> 00:01:49,350 ‫that concept information as well in our Lambda function. 45 00:01:49,350 --> 00:01:51,930 ‫So in your code, you will see, for example, a handler. 46 00:01:51,930 --> 00:01:53,100 ‫I'm using Python, 47 00:01:53,100 --> 00:01:56,760 ‫so the handler has an event and has a context, 48 00:01:56,760 --> 00:01:59,490 ‫and the event will have information, for example, 49 00:01:59,490 --> 00:02:01,800 ‫such as the source of the event or the region 50 00:02:01,800 --> 00:02:03,840 ‫of the event and so on that we can print 51 00:02:03,840 --> 00:02:07,200 ‫to the console or the context will have information, 52 00:02:07,200 --> 00:02:11,850 ‫such as the request ID, the function ARN, the function name, 53 00:02:11,850 --> 00:02:14,790 ‫the memory limits in megabytes, and then, for example, 54 00:02:14,790 --> 00:02:16,680 ‫some information about CloudWatch Logs, 55 00:02:16,680 --> 00:02:19,650 ‫such as the stream name or the group name. 56 00:02:19,650 --> 00:02:22,200 ‫So now you'll be able to choose the correct event 57 00:02:22,200 --> 00:02:25,110 ‫or context to get the specific information requested 58 00:02:25,110 --> 00:02:26,120 ‫from you at the exam. 59 00:02:26,120 --> 00:02:28,050 ‫Okay, that's it for this lecture. 60 00:02:28,050 --> 00:02:31,353 ‫I hope you liked it and I will see you in the next lecture.