I want to monitor the memory usage of my AWS Lambda functions.
Resolution
You can use Amazon CloudWatch Logs Insights, CloudWatch Lambda Insights, or the Amazon CodeGuru Profiler to monitor your Lambda functions memory usage. For more information, see Monitoring, debugging, and troubleshooting Lambda functions.
Note: To optimize your Lambda function's memory usage, see Determining the appropriate memory setting for a Lambda function.
CloudWatch Logs Insights
CloudWatch Logs Insights allows you to create a custom query syntax to search and analyze log data for memory usage metrics. For more information, see Analyzing log data with CloudWatch Logs Insights.
For example queries that determines the amount of overprovisioned memory, see Queries for Lambda logs.
Note: Your AWS account incurs charges when you run CloudWatch Logs Insights queries. 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, see Get started with Lambda Insights.
For an example workflow to track and analyze memory usage, see Example workflow to detect function anomalies.
For an example log event, see Example telemetry event in CloudWatch Lambda Insights.
Note: The CloudWatch Lambda Insights extension installation that's required for CloudWatch Lambda Insights incurs charges to your account.
CodeGuru Profiler (compatible with Python and Java)
The CodeGuru Profiler integration for Lambda for JVM and Lambda for Python collects performance data on your applications. CodeGuru Profile is compatible with applications written in Java, Python 3.7 through 3.9, and JVM languages such as Scala and other supported runtime environments.
When you profile your applications, you can monitor their metrics and receive recommendations to make them more efficient.
Related information
Operating Lambda: Use CloudWatch Logs Insights
Understanding AWS Lambda behavior using Amazon CloudWatch Logs Insights