1 00:00:00,420 --> 00:00:01,400 Okay, so we're going 2 00:00:01,400 --> 00:00:03,670 to practice using the Lambda service. 3 00:00:03,670 --> 00:00:05,860 And when you go in Lambda, you may end up on this screen 4 00:00:05,860 --> 00:00:07,080 but there's another screen I really like. 5 00:00:07,080 --> 00:00:10,418 And so if you're in your URL, you replace slash discovered 6 00:00:10,418 --> 00:00:13,060 by slash begin, you may end up on this screen, 7 00:00:13,060 --> 00:00:14,220 which I really like because it has 8 00:00:14,220 --> 00:00:16,670 an educational value I want to show you. 9 00:00:16,670 --> 00:00:18,610 So Lambda is here to help you run code 10 00:00:18,610 --> 00:00:20,170 without thinking about servers, 11 00:00:20,170 --> 00:00:23,080 and this makes it a truly serverless service. 12 00:00:23,080 --> 00:00:25,160 So the idea is that we can use any type 13 00:00:25,160 --> 00:00:27,620 of programming language we want, for example .NET Core. 14 00:00:27,620 --> 00:00:31,100 Go, Java, Node.js, Python, Ruby, or any custom runtime 15 00:00:31,100 --> 00:00:34,330 if you want to have around 10 provided by an Oprah suspect 16 00:00:34,330 --> 00:00:37,370 for example, the Lambda restaurant time as possible. 17 00:00:37,370 --> 00:00:41,010 And so from this code, you will have it written 18 00:00:41,010 --> 00:00:42,550 upload it into the lender console 19 00:00:42,550 --> 00:00:46,820 and then Erislandy will run the code for you. 20 00:00:46,820 --> 00:00:48,160 So let's take a very simple code. 21 00:00:48,160 --> 00:00:49,270 For example, Python 22 00:00:49,270 --> 00:00:51,630 we have a lender handler is going to print the event 23 00:00:51,630 --> 00:00:54,540 and then say return, hello from Lambda. 24 00:00:54,540 --> 00:00:57,380 So let's click on run and we get to hello from Lambda. 25 00:00:57,380 --> 00:00:59,650 So that means that the lender function just ran the code 26 00:00:59,650 --> 00:01:02,640 that we have provided right here. Very simple. Right! 27 00:01:02,640 --> 00:01:04,480 Next, how does Lambda functions get invoked? 28 00:01:04,480 --> 00:01:06,500 So we can click on the run button obviously 29 00:01:06,500 --> 00:01:09,810 but also we can have Lambda responded to events. 30 00:01:09,810 --> 00:01:11,850 And this is what I want to shoot you I think is really cool. 31 00:01:11,850 --> 00:01:14,670 So as we can see, events can come from various sources. 32 00:01:14,670 --> 00:01:17,270 For example, in this one, this is trimming analytics. 33 00:01:17,270 --> 00:01:20,140 And so as the streaming analytics is sending events 34 00:01:20,140 --> 00:01:21,060 into a Lambda function that 35 00:01:21,060 --> 00:01:23,410 in the function is returning hella from 36 00:01:23,410 --> 00:01:25,940 under elephant and Dial lo from that and so on 37 00:01:25,940 --> 00:01:27,640 but it's not just a streaming analytics. 38 00:01:27,640 --> 00:01:30,580 If you click on the phone right here is going to 39 00:01:30,580 --> 00:01:33,430 send a message into a mobile IOT by Ken. 40 00:01:33,430 --> 00:01:37,050 And this IOT backend will also invoke our lender function. 41 00:01:37,050 --> 00:01:40,020 Same for, if we take a photo and upload it into an S3 bucket 42 00:01:40,020 --> 00:01:43,300 for data processing, then the Lynda function we've invoked. 43 00:01:43,300 --> 00:01:44,133 But the cool thing is that 44 00:01:44,133 --> 00:01:46,770 if you start clicking a lot on one of these sources 45 00:01:46,770 --> 00:01:49,230 you can see on the right hand side, we have more cog wheels. 46 00:01:49,230 --> 00:01:52,100 So as the left hand side flow 47 00:01:52,100 --> 00:01:54,330 and invocations will index scales 48 00:01:54,330 --> 00:01:56,540 then the number of Lynda invocations and 49 00:01:56,540 --> 00:01:59,940 concurrent London functions running will be scaling as well. 50 00:01:59,940 --> 00:02:01,300 So it's really cool because that means that 51 00:02:01,300 --> 00:02:04,750 as we have more load automatically Lambda will scale 52 00:02:04,750 --> 00:02:05,990 with our load. 53 00:02:05,990 --> 00:02:07,490 And that is a whole power 54 00:02:07,490 --> 00:02:09,570 of using Lambda as a compute platform. 55 00:02:09,570 --> 00:02:11,630 And this is why alum that is serverless 56 00:02:11,630 --> 00:02:13,160 and it scales really well. 57 00:02:13,160 --> 00:02:15,290 So if we're going here, as we can see 58 00:02:15,290 --> 00:02:16,960 as the limited function is invoked 59 00:02:16,960 --> 00:02:18,700 we get more invocations over time. 60 00:02:18,700 --> 00:02:19,820 And the customer means zero 61 00:02:19,820 --> 00:02:21,150 because there's a free each year. 62 00:02:21,150 --> 00:02:25,070 And as soon as we will pass 1 million invocations 63 00:02:25,070 --> 00:02:28,670 then the Lynda function will start incurring some charges. 64 00:02:28,670 --> 00:02:30,060 So if you go in there 65 00:02:30,060 --> 00:02:32,760 and start having over 1 million invitations, here we go. 66 00:02:32,760 --> 00:02:35,120 Now we're getting some sense, as you can see 67 00:02:35,120 --> 00:02:37,760 we are at almost 2 million invocations 68 00:02:37,760 --> 00:02:40,080 and we have only 14 cents as a cost. 69 00:02:40,080 --> 00:02:40,913 So it's very, very 70 00:02:40,913 --> 00:02:45,050 very cost efficient to have a Lambda function 71 00:02:45,050 --> 00:02:46,240 and to run some workload at scale. 72 00:02:46,240 --> 00:02:47,610 So as you can, so you can play around 73 00:02:47,610 --> 00:02:49,220 and seeing that the more you have invocations 74 00:02:49,220 --> 00:02:51,930 the more the cost goes, but it's really, really controlled. 75 00:02:51,930 --> 00:02:55,470 And Linda is, can be quite accustomed saving mechanism 76 00:02:55,470 --> 00:02:56,980 if you use it at scale. 77 00:02:56,980 --> 00:02:58,500 So this is just for the introduction 78 00:02:58,500 --> 00:03:00,670 to Linda and ethically can create a function. 79 00:03:00,670 --> 00:03:04,640 We are offered with four options to create a function. 80 00:03:04,640 --> 00:03:07,440 And for this example, we're going to use a blueprint 81 00:03:07,440 --> 00:03:10,480 and in the blueprint, just type in hello, and 82 00:03:10,480 --> 00:03:13,150 we'll help you use the hello world, Python, that blueprint. 83 00:03:13,150 --> 00:03:15,460 So you click on it and we'll deploy this blueprint. 84 00:03:15,460 --> 00:03:20,080 So configure it, the function name is just demo Lambda 85 00:03:20,080 --> 00:03:23,030 because this is just our hello world for this course 86 00:03:23,030 --> 00:03:25,510 we'll create a new role with basic Lambda permission. 87 00:03:25,510 --> 00:03:28,270 So we'll leave it as the default option. 88 00:03:28,270 --> 00:03:30,120 And then here is the code that will be important 89 00:03:30,120 --> 00:03:31,270 into our function. 90 00:03:31,270 --> 00:03:34,310 So this is going to be a Lambda handler that will 91 00:03:34,310 --> 00:03:38,830 print three values into the lug and then return one value. 92 00:03:38,830 --> 00:03:40,530 So let's click on create function 93 00:03:41,710 --> 00:03:44,050 and now this function is being created 94 00:03:44,050 --> 00:03:46,433 and in the second we'll be able to run it. 95 00:03:48,110 --> 00:03:51,120 Okay. So my function is created and as we can see 96 00:03:51,120 --> 00:03:52,740 the code has the code source in here. 97 00:03:52,740 --> 00:03:55,430 In fact, click on Lynda function dot P Y and open it. 98 00:03:55,430 --> 00:03:57,600 We can see that the function could we had 99 00:03:57,600 --> 00:04:01,000 from before is now loaded into this code editor. 100 00:04:01,000 --> 00:04:02,670 So why don't we go ahead and test this function? 101 00:04:02,670 --> 00:04:04,060 So I'm going to click on tests 102 00:04:04,060 --> 00:04:06,100 and we need to create a new test events 103 00:04:06,100 --> 00:04:08,480 which is a hello world events, which contains Q1 value. 104 00:04:08,480 --> 00:04:12,670 One key, two value to Q3 value three as adjacent documents. 105 00:04:12,670 --> 00:04:16,579 So I'll call this one demo events 106 00:04:16,579 --> 00:04:18,600 and click on create. 107 00:04:18,600 --> 00:04:21,029 So now the demo event was successfully saved. 108 00:04:21,029 --> 00:04:21,863 So if I click on test 109 00:04:21,863 --> 00:04:24,540 now it was going to run the demo events 110 00:04:24,540 --> 00:04:26,690 and the response is value one 111 00:04:26,690 --> 00:04:28,294 the function log is that's value. 112 00:04:28,294 --> 00:04:31,960 One equals two value, three equals three 113 00:04:31,960 --> 00:04:36,960 which is just a result of this three print statements. 114 00:04:37,160 --> 00:04:40,260 And finally, the response value is value one again 115 00:04:40,260 --> 00:04:41,910 due to this line of code. 116 00:04:41,910 --> 00:04:43,320 So it may look, look, look how much better 117 00:04:43,320 --> 00:04:46,060 from a programmer's perspective, as you can see 118 00:04:46,060 --> 00:04:49,780 you had just some code and it was uploaded into Lambda 119 00:04:49,780 --> 00:04:51,960 and then it was run by Lambda very quickly. 120 00:04:51,960 --> 00:04:53,660 So this is a huge improvement. 121 00:04:53,660 --> 00:04:56,550 If you're a developer, as you can see to deploy the code 122 00:04:56,550 --> 00:04:59,120 and have it run, but on top of it, it runs seamlessly 123 00:04:59,120 --> 00:05:02,550 and it will scale automatically, and it is fully serverless. 124 00:05:02,550 --> 00:05:04,960 Okay. We didn't apply any service now 125 00:05:04,960 --> 00:05:06,660 in terms of built a duration. 126 00:05:06,660 --> 00:05:09,850 So if you go in here and scroll down, sorry 127 00:05:09,850 --> 00:05:12,780 then as you can see, the duration was 2.3, two millisecond. 128 00:05:12,780 --> 00:05:16,210 We've been built for three millisecond of execution 129 00:05:16,210 --> 00:05:19,100 and here's the memory size that we've provisioned. 130 00:05:19,100 --> 00:05:20,640 And the one that was used 131 00:05:20,640 --> 00:05:22,830 and how much the in it was, because this is 132 00:05:22,830 --> 00:05:25,700 the first time that we use our lender function. 133 00:05:25,700 --> 00:05:27,070 Now, if I run it again, oops. 134 00:05:27,070 --> 00:05:29,280 If I go back to my functional, excuse me 135 00:05:29,280 --> 00:05:32,420 and run this one again, as we can see now 136 00:05:32,420 --> 00:05:35,600 the function duration was one point 33 minutes, second. 137 00:05:35,600 --> 00:05:37,840 And on the right-hand side, there was no initiation 138 00:05:37,840 --> 00:05:40,190 because my lung function was ready to be used. 139 00:05:40,190 --> 00:05:42,840 Okay. So that's one way of doing things. 140 00:05:42,840 --> 00:05:44,370 Now, the other thing is on true is that's 141 00:05:44,370 --> 00:05:47,010 from this and the function we're able to configure it. 142 00:05:47,010 --> 00:05:49,040 So if I go in to general configuration 143 00:05:49,040 --> 00:05:51,860 we get some of the most important settings. 144 00:05:51,860 --> 00:05:53,360 The first one is around memory. 145 00:05:53,360 --> 00:05:55,470 So we can have the memory from anywhere 146 00:05:55,470 --> 00:06:00,470 between 128 megabytes up to 10,000, 240 megabytes of memory. 147 00:06:01,190 --> 00:06:03,210 Obviously, if you have more memory, you're going to be 148 00:06:03,210 --> 00:06:05,470 get billed more in terms of timeouts 149 00:06:05,470 --> 00:06:07,730 we can go anywhere between three seconds 150 00:06:07,730 --> 00:06:11,250 or five seconds all the way to, as you can see, 15 minutes. 151 00:06:11,250 --> 00:06:12,930 So the maximum time out is 15 minutes 152 00:06:12,930 --> 00:06:15,330 but you want to make sure that you only use it, the function 153 00:06:15,330 --> 00:06:18,400 for the time that you think is going to be used for. 154 00:06:18,400 --> 00:06:21,220 And then the execution role is the one that was created 155 00:06:21,220 --> 00:06:22,990 by Lambda in the beginning. 156 00:06:22,990 --> 00:06:25,490 Okay. So those are some of the most important settings. 157 00:06:25,490 --> 00:06:29,310 Okay. And the other thing we can look at is monitoring. 158 00:06:29,310 --> 00:06:30,270 So in monitoring 159 00:06:30,270 --> 00:06:33,120 we're able to see what is going on with the Lynda function. 160 00:06:33,120 --> 00:06:34,340 So how many times it was invoked. 161 00:06:34,340 --> 00:06:36,600 So here one time, how long it lasted 162 00:06:36,600 --> 00:06:39,810 whether or not there was errors or successes and so on. 163 00:06:39,810 --> 00:06:42,600 So it could be quite helpful, but we have integration 164 00:06:42,600 --> 00:06:45,440 with CloudWatch metrics and also CloudWatch logs. 165 00:06:45,440 --> 00:06:47,080 So right now we have nothing, but we could look 166 00:06:47,080 --> 00:06:51,380 at the CloudWatch logs right now when the function runs. 167 00:06:51,380 --> 00:06:53,240 So to do so, just a refresh 168 00:06:53,240 --> 00:06:55,040 on the right hand side, the recent invocations. 169 00:06:55,040 --> 00:06:57,190 And we can see that there's a log stream right here. 170 00:06:57,190 --> 00:06:59,970 So if I click on it, I am taken directly 171 00:06:59,970 --> 00:07:02,980 into the CloudWatch logs and we can see that 172 00:07:02,980 --> 00:07:06,200 on the clever slugs, we have all the logs 173 00:07:06,200 --> 00:07:08,140 of the invocation of this Lander function. 174 00:07:08,140 --> 00:07:08,973 And this is 175 00:07:08,973 --> 00:07:11,640 within a lab group called universal Lambda demo Lambda. 176 00:07:11,640 --> 00:07:12,700 And then when I'm, that is the name 177 00:07:12,700 --> 00:07:15,020 of my Lambda function within my region, obviously 178 00:07:15,020 --> 00:07:16,670 and we have one log stream right here. 179 00:07:16,670 --> 00:07:19,040 So we get all the logs into Lambdas. 180 00:07:19,040 --> 00:07:21,620 And other things you can try is to modify the code. 181 00:07:21,620 --> 00:07:24,080 For example, if we take this code, we go 182 00:07:24,080 --> 00:07:27,150 to the Lambda function and I will come into this line 183 00:07:27,150 --> 00:07:32,150 of code by having a hashtag and uncomment, this one 184 00:07:32,270 --> 00:07:33,550 this is going to raise an exception. 185 00:07:33,550 --> 00:07:36,500 So to do so I need to first deploy the changes 186 00:07:36,500 --> 00:07:37,750 by clicking on deploy. 187 00:07:37,750 --> 00:07:39,260 Now the trends have been deployed 188 00:07:39,260 --> 00:07:41,530 and now I can test my function. 189 00:07:41,530 --> 00:07:44,610 And in this type, we get a execution result 190 00:07:44,610 --> 00:07:46,510 which is an error or something went wrong. 191 00:07:46,510 --> 00:07:47,540 Type is exception. 192 00:07:47,540 --> 00:07:49,470 As we can see something went wrong 193 00:07:49,470 --> 00:07:53,420 which was triggered by this code or line of code right here. 194 00:07:53,420 --> 00:07:56,730 So any type of error is also will be reported by Lambda. 195 00:07:56,730 --> 00:07:58,430 And you could look into CloudWatch logs to 196 00:07:58,430 --> 00:08:02,280 understand as well where the log of the error happens with. 197 00:08:02,280 --> 00:08:03,290 I go back into clever slugs 198 00:08:03,290 --> 00:08:05,240 but there's a second log stream right here 199 00:08:05,240 --> 00:08:06,450 which I'm going to open. 200 00:08:06,450 --> 00:08:08,070 And we get this exception right here. 201 00:08:08,070 --> 00:08:10,160 So it's possible for us to go back as well 202 00:08:10,160 --> 00:08:12,160 to the logs of the exception within CloudWatch slugs 203 00:08:12,160 --> 00:08:15,000 to understand the root cause of the issue. 204 00:08:15,000 --> 00:08:16,070 So fairly easy. 205 00:08:16,070 --> 00:08:18,440 Now, if you want to make the function run again 206 00:08:18,440 --> 00:08:22,600 find you just re reverse what you did and you click on test. 207 00:08:22,600 --> 00:08:24,070 And again, now this time 208 00:08:24,070 --> 00:08:27,390 this lender execution function will work. 209 00:08:27,390 --> 00:08:29,940 So some of the less things we may want to check out 210 00:08:29,940 --> 00:08:31,550 is the fact that in here 211 00:08:31,550 --> 00:08:33,840 the runtime settings were running Python three.seven 212 00:08:33,840 --> 00:08:34,809 in this example 213 00:08:34,809 --> 00:08:37,179 but you may get an updated version maybe on your end. 214 00:08:37,179 --> 00:08:39,030 And the handler is Lynda function. 215 00:08:39,030 --> 00:08:40,059 That Lambda handler 216 00:08:40,059 --> 00:08:41,760 which is saying to look at the Lambda function 217 00:08:41,760 --> 00:08:42,592 that POI file and the function name Lambda handler. 218 00:08:44,835 --> 00:08:47,955 So if you go up, we can see the function name is dilemma 219 00:08:47,955 --> 00:08:50,370 on just construction that P Y and within it 220 00:08:50,370 --> 00:08:52,440 we have the lender on the score handler function. 221 00:08:52,440 --> 00:08:55,660 So this is why it knew to invoke this function. 222 00:08:55,660 --> 00:08:59,130 Particularly also, we have written to CloudWatch logs 223 00:08:59,130 --> 00:09:00,810 and the reason we were able to do so is 224 00:09:00,810 --> 00:09:02,450 that if we go into the configuration 225 00:09:02,450 --> 00:09:05,500 of our Lambda and go to the permission stabs 226 00:09:05,500 --> 00:09:09,450 we have a role name called demo Lambda role that was created 227 00:09:09,450 --> 00:09:12,910 for us by the Lambda console. 228 00:09:12,910 --> 00:09:14,870 And if you look at the policy itself 229 00:09:14,870 --> 00:09:18,280 we can see within the policy summary that we have access 230 00:09:18,280 --> 00:09:20,760 to right to CloudWatch logs, which is something 231 00:09:20,760 --> 00:09:23,640 you can also see right here by resource summary 232 00:09:23,640 --> 00:09:26,260 that's clever Chagos story actions and to resources 233 00:09:26,260 --> 00:09:28,870 which allow us to create Luxtreme stream and groups 234 00:09:28,870 --> 00:09:31,290 and also send the logs to CloudWatch logs. 235 00:09:31,290 --> 00:09:32,210 So this is the whole idea 236 00:09:32,210 --> 00:09:35,780 behind this permissions tabs right here. 237 00:09:35,780 --> 00:09:36,900 So that's it for this lecture. 238 00:09:36,900 --> 00:09:37,870 I hope you liked it. 239 00:09:37,870 --> 00:09:41,180 And if you are in the certified developer course on AWS 240 00:09:41,180 --> 00:09:43,300 then get ready for an extra few hours 241 00:09:43,300 --> 00:09:44,690 of content on and Dines you're nuts. 242 00:09:44,690 --> 00:09:46,850 Well, this is enough for your exam. 243 00:09:46,850 --> 00:09:47,683 I hope you liked it. 244 00:09:47,683 --> 00:09:49,480 And I will see you in the next lecture.