Ben Awad, Serverless Makes Sense Now

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey ben you made a video about why you're not making the switch to serverless and you stated your pain points so i took five minutes porting over my code and then the next 10 weeks configuring api gateway and your provisioning functions to make sure they're warm that you're kind of just missing the whole point behind serverless i'm over here thinking on a whole nother level you know what i want i'll tell you what i want this is this is big brain time okay i want my serverless functions to never cold start not even once i feel like dismissing serverless is like getting mad at a tesla for not being able to open the door serverless can be difficult to get it first but just give me 10 minutes and i'll open the door for you i'll just ask one thing if this video helps serverless make more sense for you will you share it with your community so it can make more sense for them too ben you made some great points into someone who works with serverless in my career i'm going to show you some industry standard solutions to the pain points that you and many others feel so i took five minutes porting over my code and then the next 10 weeks configuring api gateway dash space http colon and tab path hello path method and it's going to be a get method serverless deploy and bam it's that easy provisioning functions to make sure they're warm that you're kind of just missing the whole point behind serverless this is going to cost us 139 bucks with the provision concurrency you can see this is going to come in at a whopping 69 cents and you can just see where that cost saving is because now you're not worried about well do i provision 100 or 125 you can just go ahead and provision really as much as you want because the cost of calling a lambda is just so darn cheap i'm over here thinking on a whole nother level you know what i want i'll tell you what i want this is this is big brain time okay i want my serverless functions to never cold start not even once for the vast majority of use cases you won't have to worry about a cold start not even one i should introduce myself i'm dylan a cloud engineer living in oregon i work every day with companies large and small to address their computing needs and many times serverless is the best option if you say no to serverless you're going to spend a lot of time managing your infrastructure and many times you're going to pay a lot more for little to no performance gains in just a second i'll show you how to use serverless framework to make a lambda function connected to api gateway with a callable endpoint in not 10 weeks but in a couple of minutes and i'll show you how to get rid of cold starts using a plug-in from the serverless framework no more crystallized honey for you for those new to the concept of cold starts lambda functions run inside of a container and it takes some time for that container to get up and running before your code can run cold starts are the extra time it takes to get the container up and running before the actual function code executes the container will terminate after roughly 45 to 60 minutes of remaining idle according to a study done by a clyde guru and so the theory is as long as that container is running you're going to have much quicker response times let's address that first pain point of getting lambda connected to api gateway without any outside tools there's a lot to take into account however serverless framework makes this a breeze instead of spinning your head in the aws console you can use the serverless.yaml file to declare your aws infrastructure in just a few lines of code let me show you here i am in a new vs code project and what we are going to do is use the serverless framework to build out our to function and api endpoint so what you're going to do if you've never used the serverless framework list oh don't forget the i we're going to type in npm if you've never used the serverless framework you're going to type in npm install serverless and then throw a g on there if you have never done this before i've already installed this so i'm already done here so i'm just going to skip this step and then what we're going to do to make a new project is we're going to do serverless create dash dash template aws node js and what this is going to do is scaffold out a pre-made project for us and you can see in this top left we have three files git ignore handler.js which is where our function code is going to go and then below it we have our serverless.yml code and this is what's referred to as infrastructure as code where in just a couple lines we're going to declare an api gateway and at an endpoint to it let me show you how that works you can see here's some options of what you can do and down here we have our functions it's called the hello function and it's handler hello if we go over here you'll you'll notice in our handler file this is the hello function so we're just going to keep it at that you can rename it if you want and what we're going to do below this is we're going to add an api gateway endpoint to this so we can call it so what we're going to do is we're going to say events colon tab http oh whoops you need dash space http colon and tab path and we're going to call this the hello path and under that we're going to call it the method and it's going to be a get method and let's see we're going to need to also throw a slash on that and one thing you'll notice is the ammo can be a little fussy with spacing so if you're getting errors that's probably the reason you actually need to have a tab under this http we can go back and do anything we want to this lambda function we can put any code but we're just going to put dylan's lambda for ben woohoo awesome and you know you said 10 years it's such a headache and i agree with you before something like this this would have taken you know upwards of 10 minutes if not an hour if it's the first couple times you're doing this let me tell you what we're about to serverless deploy and bam it's that easy that easy really okay we can see that now in fact we do have this endpoint and this is a live endpoint i'm going to click on it i'm going to open it and i'm going to drop this screen and bring this bad boy over dylan's lambda for ben we're going to rerun that great then you rightly mention that provision concurrency defeats the idea of serverless if you're new to the idea provision concurrency means you have a certain number of lambda functions warmed up and ready to call at any time and i agree that provision concurrency defeats the idea of serverless mainly because it's expensive and you're still left guessing your traffic load you don't want to provision more than you have to so you'll still likely get cold starts in the event of a traffic spike this is where the plugin i was talking about comes in it'll keep functions warmed up for a substantially lower price than lambda's built-in provision concurrency this allows you to give yourself many more provision functions than you actually need which will allow you to not have to guess and still be able to handle the vast majority of large traffic spikes if you have a workload that's too large for what i'm about to show you that sweet kubernetes cluster that you mentioned in your video is going to be your best bet anyways but it's going to cost you a lot all right so let's just break down some pricing here so what we're going to do is we're not going to include the free tier just to give us a very transparent picture of prices so originally with provision concurrency then this is where i think you had a great point in that you're left guessing how much traffic is going to be on your website because you want to know how many lambda functions to have warm and so let's say you want to guess 100 time for which it is enabled how many hours let's say oh let's see how many hours are in a month let's say 24 times 31 uh that's 744 so let's say we want to do a whole month of provision concurrency number of requests for provision concurrency let's put it at 500 000 for you know a load with 100 provision concurrency that's very reasonable duration for each request uh let's put it at 100 amount of memory we're going to just say this is a simple function at 128 and we're going to see this is going to cost us 139 bucks with provision concurrency and now we're going to compare that to the price of the serverless plug-in which is not using aws's built-in concurrency but what it is is uh just using normal function calls but by the act of calling them all at once it's warming up all those containers and so how we're going to calculate this is the serverless plugin calls uh once every five minutes and so let's say we want to do the same thing we want to have a hundred concurrency every five minutes and so if we go over here i'll bring the calculator in picture if we clear this we say okay five minutes times 100 concurrency 5 times 12 is 60 so that means this is going to happen 12 times in an hour it's going to happen 24 times in a day and then 31 times in a month so that's going to be 446 000 calls so we're going to copy that normal number of requests it is going to be this many the duration is going to be uh 100 amount of memory 128 and we're going to show calculations and you can see this is going to come in at a whopping 69 cents and you can just see where that cost saving is because now you're not worried about well do i provision 100 or 125 you can just go ahead and provision uh really as much as you want because the cost of calling a lambda is just so darn cheap so and then if we want to go and compare that to the kubernetes cluster you were talking about we can go over and check that out okay so here we are we're gonna go to our kubernetes cluster eks so i'm going to configure it i'm just going to say one cluster and this is going to be for the month just to do a cluster that's going to cost you 73 dollars and keep in mind this is not even including the ec2 instances because i think there's so much variation in the ec2 pricing i'm not even going to try but just know that you haven't even started to pay for compute yet and so when you start to consider pricing options uh for so many use cases this serverless plug-in warm-up with the lambdas is gonna be the best solution now to take care of cold starts what we're gonna do is we're gonna add the serverless plug-in warm-up plug-in and we're going to add 10 concurrent lambda functions warm and ready to go to handle any requests coming in so what we need to do is install npm install server list plug-in warm-up and this is going to install the plug-in and once we do that the next step is to just fill out our yaml file so it configures our infrastructure properly so what we're going to have to do is we're going to have to start by adding an iem statement and this is going to allow serverless plugin to operate um on our aws account so now that we have that we need to let it know that we are using a plug-in so we'll add that in if you're following along and you're getting the errors just make sure to double check any any spaces you're using that's almost always going to be the issue okay so now what we need to do is add a uh is declare our warm up function so we're gonna say custom and this is on the documentation for the plugin if you're wondering where this is coming from great okay and now our last step is to add the warm up to our function so under events we're going to say warm up we're going to go the default enabled true and we're going to say concur in c and this is the important part we're going to put to 10. and this is saying how many functions we want to have warm at any given time and after we've done all of that we are going to deploy it so we're going to say serverless deploy and away we go we'll be right back once it deploys cool okay so we are deployed and now let's go check out the aws console to see what we have and we're going to see there that we had 10 concurrent executions we see right there we had 10 of locations and so that's a good sign that's showing that you know there is in fact 10 different functions being warmed up and there you have it sure it may not be best for the 25 000 users at once production workload but for the vast majority of use cases you won't have to worry about a cold start not even one drop any questions in the comments and i'll do my best to quickly get back to you if you want to learn more about technology that enables business start right now by subscribing and clicking the bell so we can learn together have a great day and we'll see you next time you
Info
Channel: Dylan Albertazzi
Views: 2,447
Rating: undefined out of 5
Keywords: serverless, cold starts, aws, ben awad, serverless tutorial, aws lambda tutorial, api gateway tutorial, aws tutorial
Id: yJLHaugD_WE
Channel Id: undefined
Length: 14min 36sec (876 seconds)
Published: Fri Mar 05 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.