1 00:00:00,450 --> 00:00:03,770 ‫Okay, so now let's talk about AWS Lambda. 2 00:00:03,770 --> 00:00:05,810 ‫So if we use an EC2 instance, 3 00:00:05,810 --> 00:00:07,730 ‫we have a virtual server in the cloud 4 00:00:07,730 --> 00:00:10,590 ‫but we are bounded by the amount of memory 5 00:00:10,590 --> 00:00:12,780 ‫and CPU power we give it. 6 00:00:12,780 --> 00:00:14,010 ‫It is continuously running 7 00:00:14,010 --> 00:00:16,180 ‫even though sometimes we don't use it. 8 00:00:16,180 --> 00:00:19,700 ‫And if we want to scale we can use an autoscaling group, 9 00:00:19,700 --> 00:00:20,960 ‫but that means that we need to add 10 00:00:20,960 --> 00:00:23,130 ‫or remove servers over time. 11 00:00:23,130 --> 00:00:24,750 ‫That may be a little slow 12 00:00:24,750 --> 00:00:27,840 ‫or there may be sometimes very complicated to implement. 13 00:00:27,840 --> 00:00:30,680 ‫With Lambda this is a new way to think about it. 14 00:00:30,680 --> 00:00:32,490 ‫In this case, we don't have servers, 15 00:00:32,490 --> 00:00:35,120 ‫we just have virtual functions 16 00:00:35,120 --> 00:00:37,570 ‫and these functions are limited by time. 17 00:00:37,570 --> 00:00:41,350 ‫So they're intended for shorter type of executions. 18 00:00:41,350 --> 00:00:42,650 ‫They will run on demand. 19 00:00:42,650 --> 00:00:45,080 ‫So that means that whenever we run a function, 20 00:00:45,080 --> 00:00:46,560 ‫it will be there to be run. 21 00:00:46,560 --> 00:00:48,410 ‫But whenever we don't need a function, 22 00:00:48,410 --> 00:00:51,030 ‫it will not be run and we will not be built for it. 23 00:00:51,030 --> 00:00:53,950 ‫And in case we need scaling, it's already automated 24 00:00:53,950 --> 00:00:56,060 ‫as part of the Lambda service 25 00:00:56,060 --> 00:00:59,343 ‫and this is why Lambda is a very popular service from AWS. 26 00:01:00,730 --> 00:01:03,890 ‫So the benefits of using AWS Lambda 27 00:01:03,890 --> 00:01:06,740 ‫is that the pricing is first of all super easy. 28 00:01:06,740 --> 00:01:10,820 ‫You're going to pay per request and per compute time. 29 00:01:10,820 --> 00:01:13,770 ‫And the free tier is also very generous. 30 00:01:13,770 --> 00:01:18,300 ‫So you get every month one million Lambda invocations 31 00:01:18,300 --> 00:01:21,780 ‫and 400,000 gigabytes seconds of compute time. 32 00:01:21,780 --> 00:01:24,410 ‫What this means is that you can run on Lambda 33 00:01:24,410 --> 00:01:27,440 ‫some pretty good services for free. 34 00:01:27,440 --> 00:01:31,170 ‫Now it is integrated with the whole AWS suite of services. 35 00:01:31,170 --> 00:01:33,840 ‫So we have integration with so many of the services 36 00:01:33,840 --> 00:01:37,930 ‫we've seen so far and it is very important event-driven. 37 00:01:37,930 --> 00:01:41,190 ‫So the functions will only get invoked by AWS 38 00:01:41,190 --> 00:01:42,440 ‫when something happens, 39 00:01:42,440 --> 00:01:45,190 ‫when an event happens or when needed. 40 00:01:45,190 --> 00:01:48,500 ‫So that makes Lambda the reactive type of service 41 00:01:48,500 --> 00:01:50,530 ‫which is important going into the exam. 42 00:01:50,530 --> 00:01:53,610 ‫It is fully integrated with many programming languages. 43 00:01:53,610 --> 00:01:55,970 ‫You get easy monitoring through CloudWatch. 44 00:01:55,970 --> 00:01:57,450 ‫We haven't seen what a CloudWatch is 45 00:01:57,450 --> 00:02:00,400 ‫but it will be the monitoring solution in AWS. 46 00:02:00,400 --> 00:02:03,230 ‫And finally, it's easy to get more resources per function. 47 00:02:03,230 --> 00:02:06,584 ‫We can get up to 10 gigabytes of RAM per function. 48 00:02:06,584 --> 00:02:11,140 ‫And if you do increase the RAM, it will also improve the CPU 49 00:02:11,140 --> 00:02:14,900 ‫and the network quality, so all in all very good. 50 00:02:14,900 --> 00:02:16,720 ‫Lambda can run many languages. 51 00:02:16,720 --> 00:02:19,000 ‫It can run JavaScript through Node.js, 52 00:02:19,000 --> 00:02:23,840 ‫Python, Java, C#, Golang, C# PowerShell, Ruby 53 00:02:23,840 --> 00:02:28,500 ‫and any language you want through the Custom Runtime API. 54 00:02:28,500 --> 00:02:32,050 ‫And one last runtime is called the Lambda Container Image 55 00:02:32,050 --> 00:02:34,930 ‫and this allows you to run actual Docker containers 56 00:02:34,930 --> 00:02:38,459 ‫on top of Lambda but these container images must implement 57 00:02:38,459 --> 00:02:40,820 ‫the Lambda runtime API, 58 00:02:40,820 --> 00:02:43,300 ‫which is not the case for every single Docker image. 59 00:02:43,300 --> 00:02:46,000 ‫So they are very very specific Docker images 60 00:02:46,000 --> 00:02:48,030 ‫that you can run on Lambda. 61 00:02:48,030 --> 00:02:50,850 ‫And so coming from an exam perspective, 62 00:02:50,850 --> 00:02:52,900 ‫you don't have to remember all the languages up there 63 00:02:52,900 --> 00:02:54,940 ‫but still is good for you to have a list. 64 00:02:54,940 --> 00:02:58,893 ‫But if it comes to running Docker images on AWS, 65 00:02:58,893 --> 00:03:02,010 ‫ECS and Fargate is going to be a preferred way 66 00:03:02,010 --> 00:03:04,250 ‫of running these arbitrary Docker images 67 00:03:04,250 --> 00:03:06,090 ‫so any kind of Docker images 68 00:03:06,090 --> 00:03:08,644 ‫but the Lambda Container Image does exist 69 00:03:08,644 --> 00:03:11,440 ‫if the Docker image is compliant 70 00:03:11,440 --> 00:03:13,330 ‫with the Lambda runtime API. 71 00:03:13,330 --> 00:03:14,670 ‫They maybe too specific for the exam 72 00:03:14,670 --> 00:03:17,053 ‫but I wanted to let you know of this detail. 73 00:03:17,930 --> 00:03:21,120 ‫Here is a very common use case of Lambda 74 00:03:21,120 --> 00:03:25,300 ‫which is to create a serverless thumbnail creation service. 75 00:03:25,300 --> 00:03:29,840 ‫So say we have an S3 buckets and we add images in it. 76 00:03:29,840 --> 00:03:34,270 ‫So our users are uploading a beach image into S3 buckets. 77 00:03:34,270 --> 00:03:37,240 ‫The S3 buckets will trigger a Lambda function 78 00:03:37,240 --> 00:03:38,920 ‫once the image is uploaded 79 00:03:38,920 --> 00:03:40,873 ‫and that Lambda function will take that image 80 00:03:40,873 --> 00:03:44,420 ‫and will change it to create a thumbnail. 81 00:03:44,420 --> 00:03:47,177 ‫It will push the thumbnail back into Amazon S3. 82 00:03:47,177 --> 00:03:50,890 ‫So the thumbnail is a smaller version of the image 83 00:03:50,890 --> 00:03:53,880 ‫or it will also push some metadata 84 00:03:53,880 --> 00:03:57,000 ‫about the thumbnail into DynamoDB. 85 00:03:57,000 --> 00:03:59,250 ‫That includes the image size, the image name, 86 00:03:59,250 --> 00:04:01,540 ‫the creation dates, etc, etc. 87 00:04:01,540 --> 00:04:06,540 ‫And all of this is fully event-driven and fully serverless. 88 00:04:06,660 --> 00:04:08,730 ‫With S3 we don't provision servers. 89 00:04:08,730 --> 00:04:10,660 ‫With Lambda we don't provision servers 90 00:04:10,660 --> 00:04:11,990 ‫and we've been in with Dynamo DB as well 91 00:04:11,990 --> 00:04:13,780 ‫we don't provision any servers. 92 00:04:13,780 --> 00:04:15,953 ‫So that is a great pattern because this serverless 93 00:04:15,953 --> 00:04:19,750 ‫thumbnail creation will scale it really, really well. 94 00:04:19,750 --> 00:04:23,030 ‫And we will be able to not worry 95 00:04:23,030 --> 00:04:26,010 ‫about provisioning servers to make it scale. 96 00:04:26,010 --> 00:04:28,710 ‫Now there's another very common use case for Lambda 97 00:04:28,710 --> 00:04:31,360 ‫which is to create a serverless CRON Job. 98 00:04:31,360 --> 00:04:34,010 ‫So CRON allows you to define a schedule 99 00:04:34,010 --> 00:04:37,300 ‫for example, every hour, every day or every Monday 100 00:04:37,300 --> 00:04:40,290 ‫and based on that schedule to run a script. 101 00:04:40,290 --> 00:04:44,830 ‫And by default, a CRON Job is run on an Linux AMI 102 00:04:44,830 --> 00:04:46,440 ‫so on a Linux machine. 103 00:04:46,440 --> 00:04:47,600 ‫But we are serverless 104 00:04:47,600 --> 00:04:49,870 ‫so we cannot provision an EC2 instance. 105 00:04:49,870 --> 00:04:51,850 ‫So instead we'll be using something 106 00:04:51,850 --> 00:04:54,330 ‫called CloudWatch Events or EvenBridge 107 00:04:54,330 --> 00:04:57,130 ‫and this service that we'll see later on in this course 108 00:04:57,130 --> 00:05:00,242 ‫will be triggering every one hour our Lambda function 109 00:05:00,242 --> 00:05:04,790 ‫to perform a task and effectively we have no servers in this 110 00:05:04,790 --> 00:05:06,800 ‫because CloudWatch events is serverless 111 00:05:06,800 --> 00:05:07,960 ‫and Lambda is serverless. 112 00:05:07,960 --> 00:05:10,280 ‫And so effectively we are launching a script 113 00:05:10,280 --> 00:05:12,720 ‫every hour through a Lambda function. 114 00:05:12,720 --> 00:05:15,430 ‫So I hope you can see now the trigger of it 115 00:05:15,430 --> 00:05:17,650 ‫the Lambda functions is really for serverless 116 00:05:17,650 --> 00:05:19,380 ‫functions in the cloud. 117 00:05:19,380 --> 00:05:20,770 ‫Now let's just talk about the pricing. 118 00:05:20,770 --> 00:05:23,100 ‫So you can find the Lambda pricing at this URL, 119 00:05:23,100 --> 00:05:25,000 ‫but it's very simple. 120 00:05:25,000 --> 00:05:25,990 ‫You pay per call. 121 00:05:25,990 --> 00:05:28,910 ‫So that means the first one million Lambda invocations 122 00:05:28,910 --> 00:05:32,700 ‫are free and then it's also very, very cheap. 123 00:05:32,700 --> 00:05:37,470 ‫You're going to pay $0.20 per 1 million requests thereafter. 124 00:05:37,470 --> 00:05:39,350 ‫You also going to pay for the duration. 125 00:05:39,350 --> 00:05:42,250 ‫So the free tier as I said is 400,000 gigabytes 126 00:05:42,250 --> 00:05:44,880 ‫seconds of compute time for free. 127 00:05:44,880 --> 00:05:47,370 ‫And that means it's 400,000 seconds 128 00:05:47,370 --> 00:05:49,550 ‫if the function has one gigabyte of RAM 129 00:05:49,550 --> 00:05:51,600 ‫or 3.2 million seconds 130 00:05:51,600 --> 00:05:54,750 ‫if the function has 120th megabyte of RAM. 131 00:05:54,750 --> 00:05:56,232 ‫After that you're going to pay $1 132 00:05:56,232 --> 00:05:59,130 ‫for 600,000 gigabyte seconds. 133 00:05:59,130 --> 00:06:00,960 ‫So all in all the bottom line 134 00:06:00,960 --> 00:06:05,030 ‫is that it's going to be very cheap to run Lambda on AWS. 135 00:06:05,030 --> 00:06:07,310 ‫And so it's a very popular service 136 00:06:07,310 --> 00:06:10,730 ‫to run your serverless applications and websites. 137 00:06:10,730 --> 00:06:12,650 ‫And going into the CCP exam, 138 00:06:12,650 --> 00:06:15,460 ‫you need to remember that Lambda pricing 139 00:06:15,460 --> 00:06:18,180 ‫is based on calls and duration. 140 00:06:18,180 --> 00:06:20,210 ‫So that's it for this lecture, I hope your liked it 141 00:06:20,210 --> 00:06:22,160 ‫and I will see you in the next lecture.