amazon-web-services - SNS 主题的多个电子邮件端点
问题描述
我有一个由 S3 存储桶中的 PUT 事件触发的 Lambda 函数。此功能需要向 SNS 主题的所有订阅者发送电子邮件。
Lambda 函数代码为:
import json
import boto3
print('Loading function')
s3 = boto3.client('s3')
sns = boto3.client('sns')
def lambda_handler(event, context):
bucket = event['Records'][0]['s3']['bucket']['name']
key = event['Records'][0]['s3']['object']['key']
eventname = event['Records'][0]['eventName']
sns_message = str("A new file has been uploaded in our S3 bucket. Please find the details of file uploaded belown\n\nBUCKET NAME: "+ bucket +"\nFILE NAME: " + key)
try:
if eventname == "ObjectCreated:Put":
subject= "New data available in S3 Bucket [" + bucket +"]"
sns_response = sns.publish(TargetArn='<SNS ARN ID>',Message= str(sns_message),Subject= str(subject))
except Exception as e:
print(e)
print('Error getting object {} from bucket {}. Make sure they exist and your bucket is in the same region as this function.'.format(key, bucket))
raise e
但是,仅向订阅 SNS 主题的一个电子邮件端点触发电子邮件。知道我错过了什么吗?
解决方案
我的代码中有错误。我没有使用 TopicArn,而是使用了 TargetArn。将代码更改为 TopicArn 解决了这个问题。
推荐阅读
- python - 对 Flask 函数执行阻塞操作
- python - 出现错误:在 selenium python 中定位名为 ng-star-inserted 的元素时,无法定位元素:.ng-star-inserted
- spring - 为什么 sec:authentication="name" 显示所有用户信息?
- python - TypeError:'utf8' 是 Compat32 smtplib 电子邮件错误消息的无效关键字参数
- c++ - 从 getline() 读取逗号分隔的整数
- gdb - 查找使用 qemu-arm-static 运行的程序的核心转储
- c# - '=' 附近的语法不正确
- go - 读取 Go 命令行程序的管道输入长度
- c++ - 为什么从桌面运行程序时找不到我的声音文件?
- c - 动态数组未知大小 C