Monitoring your Lambda Function Demo
Start course
2h 49m

This section of the Solution Architect Associate learning path introduces you to the core computing concepts and services relevant to the SAA-C03 exam. We start with an introduction to the AWS compute services, understand the options available and learn how to select and apply AWS compute services to meet specific requirements. 

Want more? Try a lab playground or do a Lab Challenge

Learning Objectives

  • Learn the fundamentals of AWS compute services such as EC2, ECS, EKS, and AWS Batch
  • Understanding how load balancing and autoscaling can be used to optimize your workloads
  • Learn about the AWS serverless compute services and capabilities

Fortunately, monitoring and troubleshooting with Lambda is more straightforward than with some of the other AWS compute Services. That’s because a lot of important monitoring and logging metrics are already configured with CloudWatch by default and built into the Lambda dashboard. 

Let’s take a look at some of the default metrics that are provided to you through the service. I won’t get into every metric that Lambda supports but I will call out some of the main ones. There are three main categories of metrics:

  • Invocation metrics

  • Performance metrics 

  • And concurrency metrics 

Invocation metrics are related to the outcome of the invocation. For example, there is a metric called invocations that tracks the number of times the function has been invoked. Similarly, in this category, you also have the errors metric which counts the number of failed invocations of the function. 

Performance metrics on the other hand, follow exactly what the name suggests, and provide performance details about an invocation. These metrics include duration, which measures how long the function runs in milliseconds from when it is invoked until it terminates. This category also supports the IteratorAge metric which is only used for stream-based invocations such as Amazon Kinesis. It measures in time how long Lambda took to receive a batch of records to the time of the last record written to the stream. This IteratorAge is measured in milliseconds.

Then the last category is concurrency metrics. When you want to monitor metrics for concurrency, you can use concurrent executions metric, which is a combined metric for all of your Lambda functions that you have running within your AWS account, in addition to functions with a custom concurrency limit. It calculates the total sum of concurrent executions at any point in time. 

In addition to these metrics, CloudWatch also gathers log data sent by Lambda to help you better troubleshoot and understand issues. For each function that you have running, CloudWatch will create a different log group. 

Let’s look at these in the console. To do this, I’ll click view logs in CloudWatch. If I click on log groups, you can see two different log groups, one for each of my functions. 

You can also see that each of these log group names are prefixed with aws and lambda. So in this example, we have the logs from functions S3GetObject and S3GetObjectContentType. If I click on the function named S3GetObjectContentType, you can see I have a few logs streams here. I’ll go ahead and click on the first one, and you can see I get details about the execution. 

Some of these statements here are custom logging statements that I added into my function. For example, I used the print function in python to print out the event that is passed into my function. This statement produces output that I now see in my logs. These logging statements are used to push data to CloudWatch logs automatically in addition to the managed messages that are sent by default. 

This is language dependent, so keep that in mind if you’re using a different runtime, you’ll want to look up the appropriate syntax for these custom logging statements. 

In summary, this is just the default logging and metric functionality you can use for Lambda. if you want more information - check out the documentation on monitoring with Lambda. That’s all for this one - see you next time. 

About the Author
Learning Paths

Stuart has been working within the IT industry for two decades covering a huge range of topic areas and technologies, from data center and network infrastructure design, to cloud architecture and implementation.

To date, Stuart has created 150+ courses relating to Cloud reaching over 180,000 students, mostly within the AWS category and with a heavy focus on security and compliance.

Stuart is a member of the AWS Community Builders Program for his contributions towards AWS.

He is AWS certified and accredited in addition to being a published author covering topics across the AWS landscape.

In January 2016 Stuart was awarded ‘Expert of the Year Award 2015’ from Experts Exchange for his knowledge share within cloud services to the community.

Stuart enjoys writing about cloud technologies and you will find many of his articles within our blog pages.