Logging and monitoring

Another thing that is great about the Serverless Framework is that you don't have to leave your Terminal that often to find out what's going on. Whether it's creating, testing, or deploying—there's a command for that and you can do it all inside the Terminal. The same goes for trawling the logs or checking your function error rates. 

With the serverless logs command, you can go back and see historical logs from CloudWatch logs. You can also subscribe to the log stream, which polls continuously in the background to keep your feed up to date. My favorite command to run after deploying a stack for a serverless API is one that tails the logs. Use the following command to do so:

sls logs 
--function hello
--stage dev
--startTime 2m
--tail

This command shows you the last 2 minutes of logs and then continues the feed of logs for the lambda function you've chosen to watch—hopefully the one that is currently serving the backend requests for the API. You can even add the --filter switch to prefilter the output.

This command could also be useful for a continuous integration, continuous delivery pipeline that had just updated a deployment. The idea would be that it would look for any exceptions or errors (such as internal server errors) that were present in the new logs and then make a decision about whether it should roll back the deployment or call it successful. Combine that with another simple command to roll up the invocation stats for the last 2 minutes:

sls metrics
--function hello
--stage dev
--startTime 2m

Here, we have a fairly complete suite of tools we can use to do basic monitoring on our functions.

That was a brief overview of two commands that the Serverless Framework offers for logging and monitoring. You probably have your favorite method for troubleshooting, but I hope these will help in your workflow. 

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
13.59.173.242