[英]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.