简体   繁体   English

Cloudwatch触发AWS Lambda

[英]Cloudwatch trigger to Aws lambda

I am using cloudwatch to trigger AWS Lambda. 我正在使用cloudwatch触发AWS Lambda。 Now to create this trigger first of all I have to create rule then I need to add target and then I need to add permission policy to that lambda function. 现在要创建此触发器,首先我必须创建规则,然后需要添加目标,然后需要向该lambda函数添加权限策略。 Now the problem is there is a policy length limit(20k) for each lambda function and each cloudwatch trigger increase policy length. 现在的问题是每个lambda函数都有一个策略长度限制(20k),并且每个cloudwatch触发都会增加策略长度。 So if there are around 60 cloudwatch rules my lambda can still handle all of those events as size is still less than 20k, but after that if rules increase I get http://docs.aws.amazon.com/lambda/latest/dg/API_AddPermission.html "policy length exceed exception error". 因此,如果大约有60个cloudwatch规则,由于大小仍然小于2万,我的lambda仍然可以处理所有这些事件,但是在此之后,如果规则增加,我会得到http://docs.aws.amazon.com/lambda/latest/dg /API_AddPermission.html “策略长度超出异常错误”。
I know I can delete the policy by using removePermission method but that is not efficient because if there are around 100 rules present in cloudwatch which are triggering my lambda function then my lambda function can't handle that much amount of policy length. 我知道我可以使用removePermission方法删除策略,但是效率不高,因为如果cloudwatch中大约有100条规则触发了我的lambda函数,那么我的lambda函数将无法处理那么多策略长度。

This is how I solved it. 这就是我解决的方法。

Cloudwatch Alerts --> SNS --> Lambda Cloudwatch警报-> SNS-> Lambda

No subscription, no permissions configuration needed. 无需订阅,无需权限配置。 You can create multiple different SNS notifications if you want to isolate different team based on your alerts. 如果要根据警报隔离不同的团队,则可以创建多个不同的SNS通知。

Steps: 脚步:

  1. Create SNS with a topic 创建带有主题的SNS
  2. Send Cloudwatch Alerts to SNS 将Cloudwatch警报发送到SNS
  3. Subscribe Lambda to that SNS Topic 将Lambda订阅到该SNS主题

Receive Alerts to Lambda! 接收Lambda警报!

Hope it helps. 希望能帮助到你。

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

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