**Deploying and Monitoring a Lambda Function**
To deploy a new Lambda function, we need to go to the AWS Management Console, navigate to our account, and then find the function that we just deployed. We can do this by searching for "cloudwatch dev hello" in the console. Once we've found the function, we can click on the monitoring tab to see the different metrics for this function. From here, we can also view the logs for this function call.
To view the logs, we have a few options. One way is to go directly to CloudWatch and then navigate to Logs, where we can search for the logs in the list of lambdas. Another option is to use the Serverless Framework in our terminal, by typing `sls logs -f -t` to tail the log. This allows us to keep up with changes to the function's output over time.
**Creating a CloudWatch Dashboard**
Another feature of CloudWatch that we can utilize is creating dashboards. These are visual representations of our metrics, and they allow us to see how our service is performing in real-time. To create a new dashboard, we navigate to CloudWatch and click on the "Dashboards" tab. From here, we can add widgets to our dashboard, which display our metrics.
When creating a new widget, we need to choose from a variety of options, including choosing what metric we want to view, how often the data should be updated (period), and what type of graph we want to use. We can also customize our graphs by adding numbers, annotations, or other features.
One important thing to keep in mind when creating a CloudWatch dashboard is to understand the implications of changing the period and statistics that are displayed. For example, if we change the period to 30 seconds, we may not see any data for certain metrics because there isn't enough time for them to accumulate. By carefully selecting our metric, period, and statistics, we can create a dashboard that provides us with accurate and actionable information.
**Tuning Our Dashboard**
To get the most out of our CloudWatch dashboard, we need to tune it to show only what is relevant to us. One way to do this is by changing the period of the data displayed on the graph. For example, if we want to see a snapshot of our function's performance over time, we can choose a longer period like 1 hour or 3 hours. On the other hand, if we're interested in seeing how our function performs during a specific time frame, we can select a shorter period like 30 seconds.
We should also be careful about which statistics are displayed on our graph. For example, if we're using an average statistic, we may not see any data for certain metrics because there isn't enough time for them to accumulate. By choosing the right statistic and period, we can get a clear picture of what's going on with our function.
**Common Use Cases**
One of the most common use cases for CloudWatch is deploying and monitoring AWS Lambda functions. However, it's not limited to just Lambda functions. We can also use CloudWatch to monitor other AWS services, such as EC2 instances or RDS databases.
When using CloudWatch to deploy a Lambda function, we need to consider how often our data should be updated (period) and what type of graph we want to use. By carefully selecting these options, we can create a dashboard that provides us with accurate and actionable information about our function's performance.
Another common use case for CloudWatch is creating dashboards that display metrics from multiple services at once. For example, we might create a dashboard that displays the CPU utilization of an EC2 instance, along with the latency of an RDS database. By customizing our graph to show only what's relevant to us, we can get a clear picture of how different services are performing.
Overall, CloudWatch is a powerful tool for deploying and monitoring AWS Lambda functions, as well as other AWS services. By carefully creating and tuning our dashboards, we can get accurate and actionable information about our function's performance in real-time.
"WEBVTTKind: captionsLanguage: enhello world i want to go to the very basics i want to talk about login and monitoring using cloudwatch so i want to start from the very start asking the question what is cloudwatch cloudwatch is the monitoring service from aws it helps you to keep your logs track some metrics trigger some alarms it can also record all the different changes in your infrastructure so you can do things with it like trigger lambdas if you have too many instances running or things like that it does all kind of very interesting things so it's more than just a login tool so cloudwatch help you to bring the visibility from your infrastructure into one place but i think that's one of the biggest challenges in aws to see what is going on in all these different services and clowatch is that place where you can connect everything together we have been using cloud watts to check the logs from lambdas but you can also do other things with it like check different metrics in your dynamo or even check the logs from the api gateway if you enable all resources will push some kind of information to to cloud cloudwatch but specifically for lambda cloudwatch is a great thing because when you have these execution times that is very limited and ephemeral and you want to respond as fast as possible you want that your login is not consuming thing kind of your execution time and when you're working with lambda and cloudwatch lambda will be kind of streaming asynchronously the logs to cloudwatch and it doesn't consume any extra execution time in your function and it doesn't generate any performance issue as with other libraries external libraries from aws that might generate some problems so that's why usually it's a good practice to use your cloud watch for logging in lambda and then maybe use some external library to see these logs or filter these logs or something like that but but keep the cloud watch as the login place for your lambda so now i want to show you basics of cloudwatch let's go to try out the metrics the login and the dashboards and let's go to the console to get that done let's start by creating a new empty project this is going to be a very very very simple project so just follow the steps as always to create a simple project with aws node.js as the template we are going to get into atom and do some small modifications the code is available in github but this is very simple code so i just remove all these comments to make it simpler to read and then i will create a trigger for the hello function so we can trigger this easily what we are going to do here after we create a trigger is to do a console log because that's what we want to try i will just change the message to something and this console log will just write hello in the console hello was called so very simple message so we will deploy now and we will see what happens so we'll speed up the deployment and when we finish deployment i will just trigger this function with that url let's just trigger it from postman so and we can see the message so now we can go to lambda in our account in aws in the console and then if you go there and you look for the function that you just deploy cloudwatch dev hello you can go to monitoring and there you can see the different metrics for this function and to see the logs you can just go to logs this is one way to find the logs and there you can see the logs for this call and you can see hello was called another way is a little bit more straightforward but in a way not that easy sometimes to find is to go directly to cloud watch and then go to log and there look for the logs in the list of lambdas if you have few lambdas then it becomes very easy if you have a lot like me this becomes very painful so when you find your your lambda then you can get into the log group and then you can see exactly the same another way to do that to see the logs my favorite i will say is to see the logs from the serverless framework in your terminal so you just type sls logs minus f the name of the function and minus t to tail the log so this if you keep on calling it will keep on appearing if you don't put the minus t it will just print whatever is there another thing you can do with cloudwatch as i said is to create dashboards with metrics so i will just create a new dashboard i'll put the name testing cloudwatch you can put any name you want and there you have an empty dashboard and there you can add widgets so these dashboards you can display in a screen or you can have them open to see how your service is performing and when you add a new metric you can look for the different services so we will just look for lambda and then you can look by function name and there is all the functions there then i will just look for the serverless cloudwatch and you can search so it becomes easier if you put the name of the function it just shows that it filters out the rest and then if you see on the right you'll start seeing some dots appearing those are like the only time we invoke this function so there's only one but if this is called many times then you will see lines so you can define things like the order in which these metrics are shown you can also define the period that these metrics are showing so either one second of information or five minutes or one hour and depending on that you are going to see different things the period and the statistics will make you see different things so it's important that you tune your dashboard to something that you understand so if i put 30 seconds the average it will be the average in 30 seconds but i want the sum in 30 seconds so it's a different value than the average this case is the same because i only call it once but if you have multiple for some metrics the average is good for others the sum is better and then you have some graph options you can put annotations you can define what kind of data you how you want to show the data and that's kind of the graph then you can add numbers those graphs that's something i like some things are easy to see as a number so let's just look again for the for the same function and then you can see if i change the period then the average just disappears there's not enough data so now we have it one minute and we don't have any data there so in order to get some data what i will do is i will trigger this function many times so we can see in one minute i don't know how many invocations we have this takes a while usually cloud watch is almost real time so you need sometimes to wait a little bit now if i refresh this graph you can see that there is some values and we can see that there is some invocation and also you can see now that we have called this a couple of times so if i change the period and i change the statistic you start seeing things differently so you have the amount of i don't know invocations in one minute there were four in one hour there's an eight so it's different different values so you can play a little bit with that but always be careful on what is your period and what is your metric because sometimes those numbers can be deceiving if you don't know what you're putting there so another thing you can do is you can change the period that you're showing the data so even if the metric is being displayed for every 30 seconds you can also show what is happening in the last hour in the last three hours in the last day or then you can show what happened in the last minute or in the last 15 minutes and things like that remember that you need some data this was the video for today i hope you like it if you did give a big thumbshello world i want to go to the very basics i want to talk about login and monitoring using cloudwatch so i want to start from the very start asking the question what is cloudwatch cloudwatch is the monitoring service from aws it helps you to keep your logs track some metrics trigger some alarms it can also record all the different changes in your infrastructure so you can do things with it like trigger lambdas if you have too many instances running or things like that it does all kind of very interesting things so it's more than just a login tool so cloudwatch help you to bring the visibility from your infrastructure into one place but i think that's one of the biggest challenges in aws to see what is going on in all these different services and clowatch is that place where you can connect everything together we have been using cloud watts to check the logs from lambdas but you can also do other things with it like check different metrics in your dynamo or even check the logs from the api gateway if you enable all resources will push some kind of information to to cloud cloudwatch but specifically for lambda cloudwatch is a great thing because when you have these execution times that is very limited and ephemeral and you want to respond as fast as possible you want that your login is not consuming thing kind of your execution time and when you're working with lambda and cloudwatch lambda will be kind of streaming asynchronously the logs to cloudwatch and it doesn't consume any extra execution time in your function and it doesn't generate any performance issue as with other libraries external libraries from aws that might generate some problems so that's why usually it's a good practice to use your cloud watch for logging in lambda and then maybe use some external library to see these logs or filter these logs or something like that but but keep the cloud watch as the login place for your lambda so now i want to show you basics of cloudwatch let's go to try out the metrics the login and the dashboards and let's go to the console to get that done let's start by creating a new empty project this is going to be a very very very simple project so just follow the steps as always to create a simple project with aws node.js as the template we are going to get into atom and do some small modifications the code is available in github but this is very simple code so i just remove all these comments to make it simpler to read and then i will create a trigger for the hello function so we can trigger this easily what we are going to do here after we create a trigger is to do a console log because that's what we want to try i will just change the message to something and this console log will just write hello in the console hello was called so very simple message so we will deploy now and we will see what happens so we'll speed up the deployment and when we finish deployment i will just trigger this function with that url let's just trigger it from postman so and we can see the message so now we can go to lambda in our account in aws in the console and then if you go there and you look for the function that you just deploy cloudwatch dev hello you can go to monitoring and there you can see the different metrics for this function and to see the logs you can just go to logs this is one way to find the logs and there you can see the logs for this call and you can see hello was called another way is a little bit more straightforward but in a way not that easy sometimes to find is to go directly to cloud watch and then go to log and there look for the logs in the list of lambdas if you have few lambdas then it becomes very easy if you have a lot like me this becomes very painful so when you find your your lambda then you can get into the log group and then you can see exactly the same another way to do that to see the logs my favorite i will say is to see the logs from the serverless framework in your terminal so you just type sls logs minus f the name of the function and minus t to tail the log so this if you keep on calling it will keep on appearing if you don't put the minus t it will just print whatever is there another thing you can do with cloudwatch as i said is to create dashboards with metrics so i will just create a new dashboard i'll put the name testing cloudwatch you can put any name you want and there you have an empty dashboard and there you can add widgets so these dashboards you can display in a screen or you can have them open to see how your service is performing and when you add a new metric you can look for the different services so we will just look for lambda and then you can look by function name and there is all the functions there then i will just look for the serverless cloudwatch and you can search so it becomes easier if you put the name of the function it just shows that it filters out the rest and then if you see on the right you'll start seeing some dots appearing those are like the only time we invoke this function so there's only one but if this is called many times then you will see lines so you can define things like the order in which these metrics are shown you can also define the period that these metrics are showing so either one second of information or five minutes or one hour and depending on that you are going to see different things the period and the statistics will make you see different things so it's important that you tune your dashboard to something that you understand so if i put 30 seconds the average it will be the average in 30 seconds but i want the sum in 30 seconds so it's a different value than the average this case is the same because i only call it once but if you have multiple for some metrics the average is good for others the sum is better and then you have some graph options you can put annotations you can define what kind of data you how you want to show the data and that's kind of the graph then you can add numbers those graphs that's something i like some things are easy to see as a number so let's just look again for the for the same function and then you can see if i change the period then the average just disappears there's not enough data so now we have it one minute and we don't have any data there so in order to get some data what i will do is i will trigger this function many times so we can see in one minute i don't know how many invocations we have this takes a while usually cloud watch is almost real time so you need sometimes to wait a little bit now if i refresh this graph you can see that there is some values and we can see that there is some invocation and also you can see now that we have called this a couple of times so if i change the period and i change the statistic you start seeing things differently so you have the amount of i don't know invocations in one minute there were four in one hour there's an eight so it's different different values so you can play a little bit with that but always be careful on what is your period and what is your metric because sometimes those numbers can be deceiving if you don't know what you're putting there so another thing you can do is you can change the period that you're showing the data so even if the metric is being displayed for every 30 seconds you can also show what is happening in the last hour in the last three hours in the last day or then you can show what happened in the last minute or in the last 15 minutes and things like that remember that you need some data this was the video for today i hope you like it if you did give a big thumbs\n"