简体   繁体   English

如何安排 lambda function 在另一个 lambda function 记录特定条目后运行 2 小时?

[英]How to schedule a lambda function to run 2 hours after another lambda function logs a specific entry?

I want to run a lambda function 2 hours after another lambda function logs an entry like so console.log ('ScheduleSecondFunction');我想在另一个 lambda function 2 小时后运行 lambda function 记录这样的条目console.log ('ScheduleSecondFunction');

Is there a way to do that using CloudWatch?有没有办法使用 CloudWatch 做到这一点?

I think steps to your goal could involve CloudWatch (CW) custom metric filter to detect ScheduleSecondFunction entry in your CW Logs.我认为实现您的目标的步骤可能涉及 CloudWatch (CW) 自定义指标过滤器来检测您的 CW 日志中的ScheduleSecondFunction条目。 The metric would be used to define a CW Alarm .该指标将用于定义CW 警报 When the alarm triggers it send a SNS notification to a lambda function .当警报触发时,它会向lambda function发送SNS 通知 The function would parse the alarm event and and start a Step Function with Wait state. The state would wait 2 hours and then invoke your final lambda function. function 将解析警报事件并启动步骤 Function等待state。state 将等待 2 小时,然后调用您的最终 lambda function。

There are some alternatives to the above.上面有一些替代方案。 Instead of using SNS and the second, intermediate lambda function, you could use CW Events rule to detect alarm change and trigger Step Function directly from the CW Events.您可以使用CW 事件规则检测警报变化并直接从 CW 事件触发步骤 Function,而不是使用 SNS 和第二个中间 lambda function。 This could reduce the complexity of using SNS and intermediate lambda function.这可以降低使用 SNS 和中间 lambda function 的复杂性。

Yet another possibility, could be setting up the CW Alarm with a period of 2 hours.另一种可能性是将 CW 警报设置为 2 小时。 However, I'm not sure how using 2 hour period in CW Alarm would behave in your scenario.但是,我不确定在 CW Alarm 中使用2 小时的时间段在您的场景中会如何表现。 But if this would work, then you could eliminate the Step Function, as you could trigger your final lambda function directly from the CW Alarms.但如果这可行,那么您可以消除步骤 Function,因为您可以直接从 CW 警报触发最终的 lambda function。 But its something that could be tested and verified.但它是可以测试和验证的东西。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM