How to keep AWS lambda warm (prevent cold start)

How to keep AWS lambda warm (prevent cold start)


How to keep AWS lambda warm (prevent cold start)

Avoid cold start of amazon lambda using warm-up plugin. And make aws lambda always available instead of spinning up a fresh lambda container

AWS session:    • Why Cloud and Why AWS  

Create Lambda and API gateway using serverless:   • Create Lambda and API gateway using s…  

Configure aws credentials:    • Read and Write to S3 using cmd/aws-cli  

Download aws cli: https://docs.aws.amazon.com/cli/lates

Create aws account :    • Amazon cloud- Create a free account. …  

Create users/generate access and secret key:    • Create multiple users under one accou…  

------------------------------------------------
Follow me on:
►Youtube : https://bit.ly/2W1X7zz
►Facebook : https://www.facebook.com/e.codespace
►LinkedIn : https://www.linkedin.com/in/gourabpaul
►Twitter : https://twitter.com/gourab_p
-----------------------------------------------
#awsLambda #awsServerless


Content

0.03 -> hi welcome to another code space video in our previous tutorial we have seen
4.859 -> how to write a lambda function and how to call it through API gateway for
9.69 -> details you can check the description below in this tutorial we'll discuss how
14.7 -> to keep that lambda warm so basically what happens to a lambda function if we don't
18.96 -> call it for 10 or 15 minutes of time then lambda goes into a sleep mode so
24.9 -> once you call that lambda function again through an API or an SNS that lambda
29.25 -> function takes nearly five or ten seconds of time to get up and running
32.82 -> that state is called a cold start so in order to prevent that cold start we will
37.5 -> just write another plugin for the lambda function so that basically
41.43 -> creates second lambda function which we'll call all other lambda functions so
47.1 -> for that we'll just need to go and install serverless plugin warm up
50.399 -> we'll save it in the dev dependency
60.48 -> so once it get installed we'll change the code in handler dot Js we will just
67.93 -> write if the event source is from serverless plugin warmup then just return
72.159 -> the callback so it will not perform any of the business logic and it will just
76.149 -> return that function and if it is not from the server less plug-in means if it
80.44 -> came from any SNS topic or any API gateway so the other functions will get
85.119 -> executed and in serverless.yaml we just need to keep plugging serverless plug in
93.909 -> warm up and in the function name we just need to give warm up true
99.069 -> so that will basically create another lambda function, that is kind of a
104.259 -> batch function which keeps on running and which will call the hello
107.59 -> function after like five or six minutes of time so that the hello functions
111.88 -> always keeps warm and the warmer plug in function need to have access to have
117.009 -> access we have provided I am role with these parameters so once it is done we
123.429 -> will just go and deploy it
138.17 -> so once it get deployed we can see the endpoint also we can see there are two
143.15 -> function names so one is my service test hello and another is warm-up plugin
148.19 -> we'll go and check the lamda console
157.44 -> in the lambda console you can see that there are two lambda functions if I go
164.37 -> and invoke this you can see that it returned alive so if I go and check the
173.4 -> cloud watch
182.709 -> we can see that there 2 log groups are created, if we go and first check the lambda
187.15 -> group so here we can see that my business logic has been printed
194.29 -> but the lambda warmup plugin if condition didn't run so if I go now and
199.87 -> check other log groups it still didn't generated any of the logs because the
206.799 -> lambda still not executed it takes nearly five or six minutes of time to
211.09 -> get the first warm up lambda to get executed so now we can see that the log
217.569 -> were created we just go and check the log so here we can see that warm up
223.959 -> finished with zero invoke so if there is any permission error it will throw an
228.459 -> error here so for permission errors we'll just go and add the permission
234.73 -> here IAM role statement , so we will just give resource to all and actions as lambda
241 -> invoke function and if you go and check the console of test lambdaname, here we
252.639 -> can see that the lambda warm-up function has been invoked so we can see that warm-up
257.68 -> lambda is warm these is basically the if statement. After that my business
263.169 -> logic has not been executed and it returned the call back that's all for
268.69 -> this video if you like this video then don't forget to hit the like icon
273.46 -> Thanks for watching this video

Source: https://www.youtube.com/watch?v=wzOQUAjyy0Q