[英]How to change cloudwatch SNS emails?
通过本教程,我创建了一个lambda函数,当该函数失败时,云监视警报会导致SNS使用lambda错误度量标准发送电子邮件。 我用它来检查是否有任何ec2实例有即将到来的预定事件 。 现在,这是CloudWatch和SNS在其电子邮件中发送的信息:
Alarm Details:
- Name: ec2-scheduled-events-alarm
- Description: an ec2 instance has an upcomming scheduled event
- State Change: OK -> ALARM
- Reason for State Change: Threshold Crossed: 1 datapoint (1.0) was greater than or equal to the threshold (1.0).
- Timestamp: Wednesday 12 September, 2016 00:16:54 UTC
- AWS Account: ..........
Threshold:
- The alarm is in the ALARM state when the metric is GreaterThanOrEqualToThreshold 1.0 for 300 seconds.
Monitored Metric:
- MetricNamespace: AWS/Lambda
- MetricName: Errors
- Dimensions:
- Period: 300 seconds
- Statistic: Sum
- Unit: not specified
State Change Actions:
- OK:
- ALARM: [arn:aws:sns:us-west-2:..........:ec2-scheduled-events]
- INSUFFICIENT_DATA:
我想将此消息更改为也包含来自我的lambda脚本的信息(例如列出我定义为失败的ec2实例)。 我怎样才能做到这一点? 我猜想它涉及更改“ Monitored Metric:
的输出Monitored Metric:
- Dimensions:
以某种方式。
或者更好的是,如何让我的电子邮件包含lambda函数的Log输出?
是的,您可以让您的lambda函数发布您自己的消息,该消息可以是日志信息。 您没有提到您使用的是哪种语言,因此我将使用python进行介绍。
from __future__ import print_function
import json
import boto3
import logging
import time
import datetime
logger = logging.getLogger()
logger.setLevel(logging.INFO)
def Publish():
"""
Send a message to the topic
"""
sns = boto3.client('sns')
subject = ''
message = 'Here is the message'
# You can likely insert the debugging prints from logger into the
# message
# This will have TargetArn - the arn of the topic
# Subject and message of the email. There are other parameters as
# well. Just check out boto3 sns api
sns.publish(
TargetArn='arn:',
Subject= subject,
Message= message)#of email
return
我不确定您是否能够从显示的默认SNS电子邮件中访问lambda日志中的信息。 我列出的选项可能是您的解决方案。 您将需要制作一个单独的SNS主题并同时订阅它,因此这对于您寻找的内容可能会产生过多的开销。
我希望这有帮助!
(编辑:我现在意识到9个月前您问过这个问题,所以,您可能已经知道了,糟糕。)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.