CloudWatch alarm to SNS in different region

前端 未结 2 1331
误落风尘
误落风尘 2021-02-14 09:48

I\'m trying to notify an SNS topic from a CloudWatch alarm that\'s in a different region. The reason is that I want SMS alerting, which isn\'t available in the region where my

2条回答
  •  天涯浪人
    2021-02-14 10:41

    To add to @Tartaglia's answer, here's the source of such a lambda function using Python 3, cobbled together from various sources because I don't have time to do it properly:

    import json
    import logging
    
    import boto3
    
    
    logger = logging.getLogger()
    logger.setLevel(logging.INFO)
    
    
    session = boto3.Session(region_name='eu-west-1') # EU (Ireland)
    sns_client = session.client('sns')
    
    
    def lambda_handler(event, context):
        logger.info('Received event: %s', event)
    
        for record in event['Records']:
            sns_message = record['Sns']
    
            response = sns_client.publish(
                TopicArn='YOUR TOPIC ARN HERE',
                Subject=sns_message.get('Subject', None),
                Message=sns_message.get('Message', None))
    
            logger.info('Publish response: %s', response)
    
        return 'OK'
    

提交回复
热议问题