CloudAcademy

Monitoring and Debugging Lambda Functions with Amazon CloudWatch

The course is part of these learning paths

Certified Developer – Associate Certification Preparation for AWS - June 2018
course-steps 27 certification 4 lab-steps 22 description 2
Serverless Computing on AWS for Developers
course-steps 12 certification 1 lab-steps 8
Get Started Building Cloud Solutions
course-steps 14 certification 3 lab-steps 1 quiz-steps 1
Getting Started with Serverless Computing on AWS
course-steps 8 certification 1 lab-steps 9
more_horiz See 1 more
play-arrow
Start course
Overview
DifficultyBeginner
Duration39m
Students1008

Description

In this course, we explore some of the common use cases for serverless functions and get started with implementing serverless functions in a simple application

 

Transcript

- [Lecturer] Welcome to this lecture on our getting started with serverless computing learning path, where we're looking at monitoring and debugging. In this lecture, we'll introduce the AWS Lambda CloudWatch metrics that are available to us, we'll outline how CloudWatch metrics can be used to debug an application, and we'll review how CloudWatch metrics can be used to debug and monitor our simple ordering application. CloudWatch is a service that is used to monitor the operation and performance of an AWS environment. With AWS Lambda we can use the log stream functionality of CloudWatch to monitor the execution of our functions. So, AWS Lambda includes a set of metrics that can be used to monitor the overall statistics of our functions. With CloudWatch log strings, we can get insight into the execution of our functions by using console dot log. by using console dot log. Each console dot log message will be written out to the log stream, meaning we can add messages that indicate where we are in the code. We can output the values of variables to see their state at any point during the execution. In the event of an error, we can see what happened and the structures behind it. Each execution of the function writes a minimum of three messages in the log stream. The start of the execution is logged along the time it was launched in a unique identifier called the request ID. The end of the execution is logged, and it contains the request ID along with the time the execution completed. And lastly, there is a report message that indicates the duration of the execution, the milliseconds that will be billed, and the memory allocated, and the memory used during the execution of that function. If we do nothing else and the execution succeeds, this is all we will have in the log string. If the execution fails, there will be an error message included in two messages. One that indicates the task failure with the full stack trace, and another that summarizes the error message. On a test run of our S3 restaurant ordering application, we see the standard messages along with some informational output we thought might be important to include. If there was an error during execution, or the function did not do what we expected, these messages can help. When we upload a order as adjacent file to our history bucket, the informational messages give us some insight into what happened. The first two informational messages are the S3 bucket name, and the name of the file. After these messages are written to the log stream, an error occurs. Combining these messages and the error stack trace can help us track down what went wrong. It would be pretty unfavorable to have a stack trace in production, but no additional information that can pinpoint the problem we need to fix. So the CloudWatch metrics we can get from AWS Lambda include the request account, error count and latency. The request account tells us how many times the function was executed. The error count metric tells us how many of those executions did not succeed. And the latency gives us some insight into the time it takes in milliseconds for the execution to start after it has been invoked. Like other CloudWatch metrics, we can create alarms such as sending a notification when the error count exceeds a value, say, ten times in a five minute window. Alright, that brings us to the close of this lecture. As we can see, CloudWatch provides a great complement to our AWS Lambda functions. So in summary, we've introduced the AWS Lambda CloudWatch metrics, we've outlined how CloudWatch metrics can be used to debug our simple restaurant ordering application.

About the Author

Students50447
Courses76
Learning paths28

Andrew is an AWS certified professional who is passionate about helping others learn how to use and gain benefit from AWS technologies. Andrew has worked for AWS and for AWS technology partners Ooyala and Adobe.  His favorite Amazon leadership principle is "Customer Obsession" as everything AWS starts with the customer. Passions around work are cycling and surfing, and having a laugh about the lessons learnt trying to launch two daughters and a few start ups.