I want to monitor the memory usage of my AWS Lambda functions. How do I do that?
Resolution
You can use the following AWS services and tools to monitor your Lambda functions' memory usage. For more information on monitoring function metrics, see Monitoring and observability in the Lambda operator guide.
Note: To optimize your Lambda function's memory usage, see Profiling functions with AWS Lambda Power Tuning.
Amazon CloudWatch Logs Insights
CloudWatch Logs Insights allows you to search and analyze log data for memory usage metrics using a specialized query syntax. For more information and example tutorials, see Analyzing log data with CloudWatch Logs Insights.
For an example query that determines the amount of overprovisioned memory, see the Queries for Lambda logs section of Sample queries.
Note: Running CloudWatch Logs Insights queries incurs charges to your AWS account. For more information, see Amazon CloudWatch pricing.
CloudWatch Lambda Insights
CloudWatch Lambda Insights automatically collects memory usage metrics from the Lambda functions where it's installed. For more information and example tutorials, see Using Lambda Insights.
For an example workflow to track and analyze memory usage, see Example workflow to detect function anomalies in the Lambda Developer Guide.
For an example log event, see the Example telemetry event in the Using Lambda Insights section of the CloudWatch User Guide.
Note: Installing the CloudWatch Lambda extension that's required for CloudWatch Lambda Insights incurs charges to your AWS account. For more information, see the Pricing section of Using Lambda Insights.
Amazon CodeGuru Profiler (compatible with Python and Java)
The Amazon CodeGuru Profiler integration for AWS Lambda collects performance data on your applications. It's compatible with applications written in Java, Python 3.6 through 3.9, and JVM languages such as Scala and Kotlin.
By profiling your applications, you can monitor their metrics and receive recommendations to make them more efficient. For more information on Amazon CodeGuru Profiler, see Profiling your applications that run on AWS Lambda.
Related information
Operating Lambda: Using CloudWatch Logs Insights
Understanding AWS Lambda behavior using Amazon CloudWatch Logs Insights