gpt4 book ai didi

amazon-web-services - 如何将 cloudwatch 警报连接到 lambda 函数

转载 作者:行者123 更新时间:2023-12-03 23:54:09 25 4
gpt4 key购买 nike

如何将 aws 云监视警报连接到 lambda 函数调用?

我正在以编程方式将云监视警报添加到我们通过 AWS CloudFormation 模板创建的 ELB,作为云形成堆栈的一部分。我希望将警报发送到 lambda 函数,该函数会将消息发布到 Slack。尽管警报有效,并且 SNS 配置对我来说似乎是正确的,但 lambda 函数从未被调用。

lambda 函数遵循以下示例:

https://medium.com/cohealo-engineering/how-set-up-a-slack-channel-to-be-an-aws-sns-subscriber-63b4d57ad3ea#.x2j9apedu

http://inopinatus.org/2015/07/13/hook-aws-notifications-into-slack-with-a-lambda-function/

lambda 函数有效,我可以通过 aws 控制台向其发送测试数据,从而将消息发布到 Slack。

负载均衡器是使用外观正确的云监视警报创建的:

enter image description here

警报似乎已配置为将警报发送到正确的 SNS 主题:

enter image description here enter image description here

该主题有一个 SNS 订阅,以 lambda 函数作为端点:

enter image description here

当警报触发时,将触发警报并将消息发送到正确的主题:

enter image description here

但是 lambda 函数从未被调用:

enter image description here

但是,如果我在 lambda 函数上手动添加 SNS 主题作为“事件源”,则当警报触发并发布 Slack 消息时会调用它。

enter image description here

我是否误解了如何将云 watch 警报连接到 lambda 函数?还是我遗漏了一个小细节?

如果此方法不起作用,并且将 lambda 函数连接到云监视警报的唯一方法是将 SNS 主题添加为“事件源”,那么通过 AWS CloudFormation 模板执行此操作的适当方法是什么?我没有看到修改现有资源(例如固定 lambda 函数)的明显方法。

这是我的 CloudFormation 模板:

"GenericSlackAlertSNSTopic" : {
"Type" : "AWS::SNS::Topic",
"Properties" : {
"Subscription" : [ {
"Endpoint" : "arn:aws:lambda:us-east-1:[...]:function:snsToSlack",
"Protocol" : "lambda"
} ]
}
},
"ELBNoTrafficAlarm": {
"Type": "AWS::CloudWatch::Alarm",
"Properties": {
"Namespace" : "AWS/ELB",
"AlarmDescription": "Alarm for no apparent traffic on an ELB.",
"AlarmActions": [{
"Ref": "GenericSlackAlertSNSTopic"
}],
"InsufficientDataActions": [{
"Ref": "GenericSlackAlertSNSTopic"
}],
"MetricName": "RequestCount",
"Statistic": "Sum",
"Dimensions" : [ {
"Name" : "LoadBalancerName",
"Value" : { "Ref" : "ElasticLoadBalancer" }
} ],
"Period": "60",
"EvaluationPeriods": "3",
"Threshold" : "10",
"ComparisonOperator": "LessThanOrEqualToThreshold"
}
}

谢谢!

-尼尔

最佳答案

AWS 发布了(大约 3 天前)在 python 和 nodejs 中使用 lambda 与 AWS Cloudwatch 进行 slack 集成的蓝图:https://aws.amazon.com/blogs/aws/new-slack-integration-blueprints-for-aws-lambda/

话虽这么说,我也遇到了和你一样的问题,按照蓝图中提到的步骤,我没有收到警报,直到我在 lambda 函数上手动添加 SNS 主题作为“事件源”。进一步的调查让我想到了这个问题:Can't create a SNS Event source on a Lambda function using CloudFormation

最后阅读 AWS 文档:1) http://docs.aws.amazon.com/lambda/latest/dg/intro-core-components.html

Amazon SNS maintains the event source mapping via topic subscription configuration (there is no AWS Lambda API to configure this mapping).

2) http://docs.aws.amazon.com/sns/latest/dg/sns-lambda.html

Configuring Amazon SNS with Lambda Endpoints with the AWS Management Console

得出结论,目前的订阅应该通过 AWS 管理控制台完成

摘要:目前使用 Lambda 终端节点配置 Amazon SNS 的唯一方法是通过 AWS 管理控制台

奖励:具有相同答案的类似问题:AWS Lambda scheduled event source via cloudformation

关于amazon-web-services - 如何将 cloudwatch 警报连接到 lambda 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34800976/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com