【问题标题】:Multiple Email Endpoints of a SNS TopicSNS 主题的多个电子邮件端点
【发布时间】:2021-08-16 20:10:20
【问题描述】:

我有一个由 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 主题的一个电子邮件端点触发电子邮件。知道我错过了什么吗?

【问题讨论】:

    标签: amazon-web-services aws-lambda boto3 amazon-sns


    【解决方案1】:

    我的代码中有错误。我没有使用 TopicArn,而是使用了 TargetArn。将代码更改为 TopicArn 解决了这个问题。

    【讨论】:

      猜你喜欢
      • 2016-04-08
      • 2019-07-21
      • 2022-10-20
      • 2016-01-19
      • 1970-01-01
      • 2021-11-17
      • 2021-08-25
      • 1970-01-01
      • 2021-04-02
      相关资源
      最近更新 更多