简体   繁体   English

使用SQS或SNS发送电子邮件

[英]Send emails using SQS or SNS

I have a web application that should send emails to admin users when something happens in the application. 我有一个Web应用程序,应该在应用程序发生某些事情时向管理员用户发送电子邮件。 For instance, a new user is registered. 例如,注册了新用户。

I would like to avoid having the logic of building/sending the emails inside of the application. 我想避免在应用程序内部构建/发送电子邮件的逻辑。 I would rather prefer that the application publishes a message in a queue, and then, there is another system listening and reacting properly to send the emails. 我宁愿首选应用程序在队列中发布消息,然后,还有另一个系统正在监听并正确响应以发送电子邮件。

The flow would be something like that. 流程就是这样的。

  • The application publishes a message in a queue (SQS or SNS??) 应用程序在队列中发布消息(SQS或SNS ??)
  • A lambda function is trigger. lambda函数是触发器。 Lambda reads the message and calls SES. Lambda读取消息并调用SES。
  • SES sends the email SES发送电子邮件

I'm not sure if that is the best way of doing this. 我不确定这是否是最佳方式。 I have read that there is a gap between SQS and Lambda. 我读过SQS和Lambda之间存在差距。 Would it be better with SNS? SNS会更好吗?

What would be the proper flow? 适当的流量是什么?

App -> SQS -> Lambda -> SES App - > SQS - > Lambda - > SES

or 要么

App -> SNS -> Lambda -> SES App - > SNS - > Lambda - > SES

Maybe something else? 也许别的什么?

Please, take into consideration that the idea is always to abstract the web application from all that logic. 请考虑到这个想法总是从所有逻辑中抽象出Web应用程序。 The web application would only publish a message somewhere. Web应用程序只会在某处发布消息。 Then the magic happens in the background. 然后魔术发生在后台。

Based on your description, I'd propose the following architecture: 根据您的描述,我建议采用以下架构:

App -> SQS -> Lambda -> SES

I'd use SQS to execute the Lambda function from the app or use Cron job worker to run it periodically as a worker on the queue. 我将使用SQS从应用程序执行Lambda函数,或使用Cron作业工作程序作为队列中的工作程序定期运行它。

This architecture decouples the App from the mailing service, provides asynchronous invocation and queueing. 此体系结构将App与邮件服务分离,提供异步调用和排队。 If you need to send larger payloads, use S3 to store these objects and just pass the keys in SQS messages to your Lambda . 如果需要发送更大的有效负载,请使用S3存储这些对象,并将SQS消息中的密钥传递给Lambda

Take SNS out of the equation for email, as you need to be a subscriber to a topic to receive notifications. 将SNS排除在电子邮件的等式之外,因为您需要成为主题的订阅者才能接收通知。 It's really for AWS related event notification. 它实际上适用于AWS相关事件通知。

With SQS, you have to deal with Limits Related to Messages . 使用SQS,您必须处理与消息相关的限制 Default max message size is 256kb unless you use a special SDK then it is 2GB. 默认最大邮件大小为256kb,除非您使用特殊的SDK然后它是2GB。

Consider a 3rd option. 考虑第三种选择。 App -> DB -> Lambda -> SES App - > DB - > Lambda - > SES

A mail queue in the DB is an easy table structure, and you have Lambda scan it on a scheduled or event-driven basis and process mails via SES. 数据库中的邮件队列是一种简单的表结构,您可以在计划或事件驱动的基础上对其进行Lambda扫描,并通过SES处理邮件。 And this way there is no SQS message limit. 这种方式没有SQS消息限制。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM