在将消息推送到 AWS Simple Queue Service 时发送电子邮件

Send email when message being pushed to AWS Simple Queue Service

我正在处理多个日志文件,并且在出现问题时放置了一段代码,同时,我将一条包含错误详细信息的消息推送到 AWS SQS。现在我想在消息被推送到 SQS 时立即给自己发送一封电子邮件。 早些时候我尝试使用 SES。我放置了 SES 电子邮件发送代码,但 SQS 没有在其中发挥作用。 我可以做些什么来实现我的用例?

except: 
            #this part runs for any corrupted file
            sqs_msg_response = queue_client.send_message(MessageBody='Data Processing num_failed')
            print('messageID',sqs_msg_response.get('MessageId'))
            subject = 'Data file is not processed'
            body='''the {}file is not processed at the time{}'''.format(string,current_time)
            message = {"Subject":{"Data":subject},"Body":{"Html":{"Data":body}}}
            email_response = email_client.send_email(
            Source="xyz@gmail.com",
            Destination={
                "ToAddresses":[
                    "abc@gmail.com",
                    ]
                },
            Message=message
            )

上面我实现了但是SQS是独立的,SES是独立的。现在,我想在将消息推送到 SQS 电子邮件并发送到提供的电子邮件 ID 后立即实施。

解决此类问题的常规模式是结合使用 Amazon SQS 和 Amazon SNS

  1. 创建 SNS 主题
  2. Add the SQS queue as a target进入正题
  3. 将电子邮件订阅添加为主题的第二个目标
  4. 修改您的应用程序以将消息放在主题而不是队列上

这样,主题将每条消息放入队列并同时发送一封电子邮件。