[英]CloudWatch alarm to SNS in different region
I'm trying to notify an SNS topic from a CloudWatch alarm that's in a different region. 我正在尝试从位于不同区域的CloudWatch警报通知SNS主题。 The reason is that I want SMS alerting, which isn't available in the region where my services are.
原因是我想要短信提醒,这在我的服务所在的地区是不可用的。 If I enter the ARN of the subscription and save the changes in the console, I get "There was an error saving the alarm. Please try again."
如果我输入订阅的ARN并在控制台中保存更改,我会收到“保存警报时出错。请再试一次。” Trying again does not help.
再试一次没有用。 Using a topic in the local region does work, but that's not what I need.
在本地区域使用主题确实有效,但这不是我需要的。
Is there a way to notify a topic in a different region? 有没有办法通知不同地区的主题? If not, is there another easy way I can achieve my goal?
如果没有,还有另一种简单的方法可以实现我的目标吗?
Didn't find any docs that explicitly say this can't be done but tried to set an SNS from us-east-1 as an action of an alarm in eu-west-1 using the CLI and I got this: 没有找到任何明确表示无法完成的文档,但尝试使用CLI在us-east-1中设置SNS作为eu-west-1中的警报动作,我得到了:
An error occurred (ValidationError) when calling the PutMetricAlarm operation: Invalid region us-east-1 specified. Only eu-west-1 is supported.
So I'll assume it's not supported. 所以我认为它不受支持。
To get the functionality you need you can use AWS Lambda. 要获得所需的功能,您可以使用AWS Lambda。 Lets say your service is in a region where SMS is not supported, I'll use eu-central-1 as an example.
假设您的服务位于不支持SMS的区域,我将使用eu-central-1作为示例。
Setup would go like this: 安装程序将如下所示:
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: 要添加到@Tartaglia的答案,这里是使用Python 3的这种lambda函数的来源,从各种来源拼凑而成,因为我没有时间正确地执行它:
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'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.