DEV Community

shimo for AWS Community Builders

Posted on • Updated on

Find AWS Lambda Functions Executed in a Specific Time Range Using Boto3 and CloudWatch Logs

Motivation

At times, we need to identify which Lambda functions were executed within a specific time range, primarily for troubleshooting or monitoring purposes.

In this blog, I'll share a Python Boto3 script that allows you to search and discover which Lambda functions have execution results in their CloudWatch logs.

(Note: You can also use CloudWatch Logs Insights to query the logs. If the number of target log groups is smaller than the maximum limit of 50, using Logs Insights on the Console might be more convenient.)

Code

Example results

This is the example of the results. I've found that the Lambda function test-my2 was executed twice (2 events) between 2023-04-30 20:10:00+09:00 and 2023-04-30 21:10:00+09:00.

Start. 2023-04-30 21:20:37
===
From 2023-04-30 20:10:00+09:00
To 2023-04-30 21:10:00+09:00
Check 65 log groups... wait...
---
/aws/lambda/test-my2
2 events
===
Finished.  2023-04-30 21:21:17
Enter fullscreen mode Exit fullscreen mode

Appendix

You can also use logGroupNamePattern instead of logGroupNamePrefix. (These are mutually exclusive. ) Note that boto3 version after 1.26.17 is required.

Refer to the boto3 document.

Top comments (0)