如何更改cloudwatch SNS电子邮件?
问题描述:
使用此tutorial我创建了一个lambda函数,当它失败时,云计时警报会导致SNS使用lambda错误度量标准发送电子邮件。我正在使用它来检查是否有任何ec2实例正在upcomming scheduled events。眼下,这是信息的CloudWatch和SNS在发送电子邮件的:如何更改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:
我想改变这条消息也包含来自我的拉姆达脚本信息(如列明EC2实例我定义为不及格)。我怎样才能做到这一点?我猜测它涉及以某种方式改变Monitored Metric:
- Dimensions:
的输出。
或更好的但我怎么才能让我的电子邮件包含我的lambda函数的日志输出?
答
是的,你可能会让你的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个月前问过这个问题,所以你可能已经想通了,哎呀。)