0

이것을 사용하여 tutorial 람다 함수를 만들었습니다. 클라우드 감시 알람에 실패하면 SNS가 람다 오류 측정 항목을 사용하여 이메일을 발송합니다. 나는 어떤 ec2 인스턴스가 상향 조정되어 있는지 확인하기 위해 이것을 사용하고있다. scheduled events. (I 실패로 정의 등의 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: 
나는 또한 내 람다 스크립트에서 정보를 포함하는 메시지를 변경하려면

: 지금이 CloudWatch에서와 SNS가 이메일에 전송하는 정보입니다. 어떻게해야합니까? 나는 그것이 어떻게 든 어떻게 Monitored Metric:- Dimensions:의 출력을 변경하는 것입니다 추측하고있어.

또는 더 나은 방법은 내 전자 메일에 람다 함수의 로그 출력이 포함되도록하려면 어떻게해야합니까?

답변

0

예, 람다 함수가 로그 정보가 될 수있는 자신의 메시지를 게시 할 수 있습니다. 당신은 어떤 언어를 사용하는지 언급하지 않았기 때문에 파이썬을 사용하여 설명 할 것입니다.

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 이메일에서 람다 로그의 정보에 액세스 할 수 있는지 확실하지 않습니다. 나열된 옵션이 솔루션 일 수 있습니다. 별도의 SNS 주제를 만들고 구독해야하므로 찾고있는 내용에 너무 많은 오버 헤드가 발생할 수 있습니다.

도움이 되었기를 바랍니다.

(편집 : 이제 9 개월 전에이 질문에 답했습니다. 따라서 이미 알아 냈을 것입니다.)

관련 문제