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
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
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.

原文链接:Find AWS Lambda Functions Executed in a Specific Time Range Using Boto3 and CloudWatch Logs

© 版权声明
THE END
喜欢就支持一下吧
点赞10 分享
The only thing standing between you and your dreams is a lot of hard work.
横跨在你和你的梦想之间的唯一的东西就是奋力拼搏
评论 抢沙发

请登录后发表评论

    暂无评论内容