简体   繁体   English

AWS Lambda函数被CloudWatch事件触发了两次

[英]AWS Lambda function was trigger twice by CloudWatch event

I deployed a service written in Python2.7 using AWS Lambda, and it's about extracting data from some pages and sending results to a web app. 我使用AWS Lambda部署了用Python2.7编写的服务,它是关于从某些页面提取数据并将结果发送到Web应用程序。 The service is triggered by the AWS CloudWatch event (fixed rate of 5 mins). 该服务由AWS CloudWatch事件触发(固定速率为5分钟)。

However, I found out sometimes the service was triggered twice at a time. 但是,我发现有时一次会触发两次该服务。 I got this because there were two log stream printed the same data and result but with different RequestID's. 我得到这个是因为有两个日志流打印了相同的数据和结果,但是具有不同的RequestID。 And the database had duplicate data, which showed that both worked successfully. 而且数据库中有重复的数据,这表明两者都可以成功工作。 It looked like the service was triggered twice almost at the same time for no reasons. 似乎该服务几乎是无缘无故地同时触发了两次。

Does anyone experience the same thing, and how do you fix it? 有人遇到过同样的事情吗?如何解决? Or, is there a way to limit only one function can be executed at a time. 或者,是否有办法限制一次只能执行一个功能。

Yes. 是。 Some AWS services have SLA of at least once delivery . 某些AWS服务具有至少一次交付的 SLA。 I have experienced this with CloudWatch and CloudTrail . 我在CloudWatchCloudTrail经历了这CloudTrail I do not know if you can limit it only once. 我不知道您是否只能限制一次。 You have to check if the data has been processed already. 您必须检查数据是否已经被处理。 I overcame this by making boto3 calls in my python code before processing the data. 我通过在处理数据之前在我的python代码中进行boto3调用来克服了这一问题。 Without knowing your situation, it is difficult to suggest a solution. 不了解您的情况,很难提出解决方案。

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

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