1 00:00:06,198 --> 00:00:10,200 - Now let's review an introduction to AWS Lambda. 2 00:00:10,200 --> 00:00:15,200 With AWS Lambda we gain access to serverless computing, 3 00:00:15,330 --> 00:00:18,170 now of course serverless is a hot topic these days 4 00:00:18,170 --> 00:00:21,860 and let's keep in mind that there's much more 5 00:00:21,860 --> 00:00:24,560 to serverless than just Lambda. 6 00:00:24,560 --> 00:00:28,350 Lambda is just one small part of the serverless 7 00:00:28,350 --> 00:00:31,880 sort of movement and Lambda would give us 8 00:00:31,880 --> 00:00:34,630 what we might call functions as a service 9 00:00:34,630 --> 00:00:39,140 and so by serverless, what we mean is that 10 00:00:39,140 --> 00:00:41,440 even though we know somewhere out there 11 00:00:41,440 --> 00:00:42,820 in an AWS data center, we know that 12 00:00:42,820 --> 00:00:46,160 there is a server running this code, 13 00:00:46,160 --> 00:00:48,530 from our perspective as a customer, 14 00:00:48,530 --> 00:00:53,310 as an organization, there is no server for us to manage. 15 00:00:53,310 --> 00:00:56,418 We're just writing code and allowing AWS 16 00:00:56,418 --> 00:00:58,623 to essentially execute that code. 17 00:00:59,490 --> 00:01:02,680 And so, Lambda is great for all kinds 18 00:01:02,680 --> 00:01:04,410 of different use cases. 19 00:01:04,410 --> 00:01:08,920 We could run scheduled tasks, microservices, 20 00:01:08,920 --> 00:01:12,240 event handlers, all kinds of different things 21 00:01:12,240 --> 00:01:14,550 we can run on AWS Lambda. 22 00:01:14,550 --> 00:01:16,690 Anything that can be decomposed 23 00:01:16,690 --> 00:01:20,180 into small targeted functions, 24 00:01:20,180 --> 00:01:22,470 could be written to use Lambda. 25 00:01:22,470 --> 00:01:25,560 Now, one of the things that I'd like 26 00:01:25,560 --> 00:01:28,870 to point out is that I see a lot of folks 27 00:01:28,870 --> 00:01:33,460 coming to Lambda, or coming to AWS looking to use Lambda, 28 00:01:33,460 --> 00:01:36,420 but still in a mindset of like traditional 29 00:01:36,420 --> 00:01:38,780 enterprise computing where you're creating 30 00:01:38,780 --> 00:01:40,870 these very large applications. 31 00:01:40,870 --> 00:01:42,770 Right so, we're not going to take 32 00:01:44,820 --> 00:01:48,300 this large enterprise java application 33 00:01:48,300 --> 00:01:50,990 comprised of thousands of functions 34 00:01:50,990 --> 00:01:53,680 across hundreds of classes and objects, 35 00:01:53,680 --> 00:01:55,290 and squeeze that into Lambda. 36 00:01:55,290 --> 00:01:57,440 That's not what we're talking about. 37 00:01:57,440 --> 00:02:00,180 With Lambda, we create functions 38 00:02:00,180 --> 00:02:02,300 and we call them functions because 39 00:02:02,300 --> 00:02:04,080 that's what they are. 40 00:02:04,080 --> 00:02:05,300 Just like we might write 41 00:02:05,300 --> 00:02:07,710 a piece of software is a collection 42 00:02:07,710 --> 00:02:10,060 of functions or classes and objects, 43 00:02:10,060 --> 00:02:11,770 the same is true with Lambda. 44 00:02:11,770 --> 00:02:14,840 So we might decompose those enterprise applications 45 00:02:14,840 --> 00:02:18,450 into various functions and then our software 46 00:02:18,450 --> 00:02:21,253 becomes a collection of functions. 47 00:02:22,570 --> 00:02:24,750 And so, with Lambda, 48 00:02:24,750 --> 00:02:29,293 we pay for compute time per 100 milliseconds. 49 00:02:30,370 --> 00:02:32,720 Now of course the more memory we use, 50 00:02:32,720 --> 00:02:34,960 the more we pay, so there is a relationship 51 00:02:34,960 --> 00:02:38,400 between the amount of memory that we use 52 00:02:38,400 --> 00:02:41,573 and the length of time that an application runs for. 53 00:02:42,850 --> 00:02:46,773 So, we can create functions in several different ways. 54 00:02:48,040 --> 00:02:51,060 We can use the inline editor which 55 00:02:51,060 --> 00:02:54,290 is available to us in the AWS console, 56 00:02:54,290 --> 00:02:55,890 and by using the inline editor 57 00:02:55,890 --> 00:02:58,450 we have a pretty quick and easy way 58 00:02:58,450 --> 00:03:01,280 of writing out a particular function. 59 00:03:01,280 --> 00:03:03,790 But probably the more common way 60 00:03:03,790 --> 00:03:06,973 is to upload a zip file and so, 61 00:03:10,677 --> 00:03:14,730 If our function needs say, other dependencies, 62 00:03:14,730 --> 00:03:18,260 other packages, then those need to be included 63 00:03:18,260 --> 00:03:19,990 with our code and the only way 64 00:03:19,990 --> 00:03:23,203 to do that is by uploading a zip file. 65 00:03:25,950 --> 00:03:29,300 And so with Lambda, once we create a function, 66 00:03:29,300 --> 00:03:31,690 we then invoke those functions 67 00:03:31,690 --> 00:03:34,130 and we can invoke them programmatically 68 00:03:34,130 --> 00:03:38,730 or even manually through the CLI tools or the SDK, 69 00:03:38,730 --> 00:03:41,000 or perhaps the most common way 70 00:03:41,000 --> 00:03:43,080 and perhaps one of the most powerful ways, 71 00:03:43,080 --> 00:03:45,730 is to leverage events. 72 00:03:45,730 --> 00:03:47,790 Events can come from all kinds 73 00:03:47,790 --> 00:03:50,267 of different places within AWS. 74 00:03:51,620 --> 00:03:54,493 A classic example of an event might be, 75 00:03:54,493 --> 00:03:58,900 to leverage Amazon S3 event notifications. 76 00:03:58,900 --> 00:04:02,583 So with S3, we have a bucket that we can store 77 00:04:02,583 --> 00:04:06,450 objects in, and we'll talk more about S3 later on, 78 00:04:06,450 --> 00:04:09,870 but as we upload things to that bucket, 79 00:04:09,870 --> 00:04:11,310 that would be an event. 80 00:04:11,310 --> 00:04:13,710 As we delete something, that would be an event. 81 00:04:13,710 --> 00:04:16,260 And so whatever is happening in that bucket, 82 00:04:16,260 --> 00:04:18,750 those events can each be used 83 00:04:18,750 --> 00:04:22,090 to trigger Lambda functions in response, 84 00:04:22,090 --> 00:04:24,090 and the Lambda function could then 85 00:04:24,090 --> 00:04:27,560 retrieve that data from s3 and go on 86 00:04:27,560 --> 00:04:30,383 to perform some type of processing. 87 00:04:31,290 --> 00:04:35,870 And once these functions are invoked 88 00:04:35,870 --> 00:04:39,037 and they start to execute, AWS handles 89 00:04:39,037 --> 00:04:41,920 all of the underlying infrastructure. 90 00:04:41,920 --> 00:04:45,010 Again, we know that there's a server somewhere, 91 00:04:45,010 --> 00:04:47,010 that is actually executing, you know, 92 00:04:47,010 --> 00:04:50,620 the CPU cycle is responsible for making our function work, 93 00:04:50,620 --> 00:04:52,354 but we don't have to manage it. 94 00:04:52,354 --> 00:04:57,354 AWS manages that actual underlying machines. 95 00:04:57,531 --> 00:05:00,500 AWS handles the deployment of our code, 96 00:05:00,500 --> 00:05:02,777 and so getting our code to that machine 97 00:05:02,777 --> 00:05:06,840 in order to be executed, Amazon handles that. 98 00:05:06,840 --> 00:05:08,913 And Amazon handles the scaling, 99 00:05:13,300 --> 00:05:16,690 We could invoke, one function, one time. 100 00:05:16,690 --> 00:05:19,460 we could invoke two functions, 101 00:05:19,460 --> 00:05:22,190 each of them thousands of times, right? 102 00:05:22,190 --> 00:05:25,310 So we could have, the default soft limit 103 00:05:25,310 --> 00:05:30,120 for Lambda is 1000 concurrent executions, right? 104 00:05:30,120 --> 00:05:31,880 And If you were to lift that, to say, 105 00:05:31,880 --> 00:05:35,200 two or three or four thousand concurrent executions, 106 00:05:35,200 --> 00:05:39,010 AWS will handle and do all that's necessary 107 00:05:39,010 --> 00:05:41,950 to handle the scaling, to make that happen. 108 00:05:41,950 --> 00:05:44,920 And so here in this particular example, 109 00:05:44,920 --> 00:05:48,720 we have a piece of Python code, 110 00:05:48,720 --> 00:05:50,850 a short piece of Python code that, 111 00:05:50,850 --> 00:05:53,180 we might write to be, let's say, 112 00:05:53,180 --> 00:05:57,290 a Hello, World! or a simple example of a Lambda function. 113 00:05:57,290 --> 00:06:00,970 And within there, I just wanted to point out, 114 00:06:00,970 --> 00:06:03,530 that within that code you can see 115 00:06:03,530 --> 00:06:07,120 that we are defining a handler, right? 116 00:06:07,120 --> 00:06:09,960 That's a function and we need to tell 117 00:06:09,960 --> 00:06:12,320 the Lambda service, the name of that 118 00:06:12,320 --> 00:06:15,720 handler function and that handler receives 119 00:06:15,720 --> 00:06:17,120 a couple of different arguments, 120 00:06:17,120 --> 00:06:19,000 in this case, event and context 121 00:06:19,000 --> 00:06:21,690 and that's how our Lambda function 122 00:06:21,690 --> 00:06:25,480 can receive data in order to do it's processing 123 00:06:25,480 --> 00:06:29,143 and how using the context parameter 124 00:06:29,143 --> 00:06:31,250 is how we can communicate back 125 00:06:31,250 --> 00:06:33,337 to the Lambda service that our function 126 00:06:33,337 --> 00:06:37,830 was either successful or our function failed. 127 00:06:37,830 --> 00:06:42,830 And so, we take our code and we give our code 128 00:06:43,620 --> 00:06:46,270 to the Lambda service and in doing so 129 00:06:46,270 --> 00:06:49,100 we specify the run time, 130 00:06:49,100 --> 00:06:54,067 be it Python, Node.js, Java or C#, 131 00:06:55,150 --> 00:06:57,770 we specify the memory that we might need, 132 00:06:57,770 --> 00:07:02,390 anywhere from 128 megs all the way up to three gigs, 133 00:07:02,390 --> 00:07:06,060 and we also specify the execution timeout, 134 00:07:06,060 --> 00:07:08,610 anywhere from a few seconds all the way up 135 00:07:08,610 --> 00:07:11,270 to 300 seconds or five minutes. 136 00:07:11,270 --> 00:07:12,740 So that's another thing to keep in mind 137 00:07:12,740 --> 00:07:16,740 that Lambda does have those limitations, 138 00:07:16,740 --> 00:07:17,909 up to three gigs of memory, 139 00:07:17,909 --> 00:07:21,410 up to five minutes of execution time. 140 00:07:21,410 --> 00:07:25,719 So, if your application needs more memory or more time, 141 00:07:25,719 --> 00:07:28,604 then Lambda is probably not an option. 142 00:07:28,604 --> 00:07:31,890 Once we have our code, we have our run time, 143 00:07:31,890 --> 00:07:35,270 memory limit and execution timeout set, 144 00:07:35,270 --> 00:07:38,073 that gives us a Lambda function. 145 00:07:38,073 --> 00:07:41,853 We can then invoke that Lambda function. 146 00:07:43,480 --> 00:07:47,073 Again, either programmatically, manually or through events. 147 00:07:48,010 --> 00:07:50,250 And we can invoke that function 148 00:07:50,250 --> 00:07:53,620 pretty much as many times as we want. 149 00:07:53,620 --> 00:07:56,190 And Amazon, every time it's invoked, 150 00:07:56,190 --> 00:07:59,340 Amazon handles the deployment of our code, 151 00:07:59,340 --> 00:08:03,670 the execution of the code and the collection of logs, 152 00:08:03,670 --> 00:08:06,520 and we're gonna talk about log collection later on, 153 00:08:06,520 --> 00:08:08,660 but in this scenario with AWS Lambda, 154 00:08:08,660 --> 00:08:10,050 the beautiful thing is that, 155 00:08:10,050 --> 00:08:12,900 all we have to do is write code. 156 00:08:12,900 --> 00:08:16,730 Give the code to AWS, configure a few things, 157 00:08:16,730 --> 00:08:19,393 and then allow AWS to handle the rest.