简体   繁体   English

发送确认电子邮件,SQS或SNS AWS?

[英]Send confirmation email, SQS or SNS aws?

I have a web application where users can register to it. 我有一个Web应用程序,用户可以在其中注册。
I need to send them a confirmation email (and eventually a sms), in this case would it better to use SQS with a beanstalk worker process or SNS ? 我需要向他们发送确认电子邮件(并最终发送一条短信),在这种情况下,将SQS与beantalk worker进程或SNS一起使用会更好吗?

Are there any advantage over the two ? 两者有什么优势吗?

SNS and SES can confuse the use cases sometimes. SNS和SES有时会混淆用例。 Like the names say, SNS is for notifications, that can be via email, push notifications, sms, and others, while SES is just for emails. 就像名称中所说的那样,SNS用于通知,可以通过电子邮件,推送通知,短信等进行,而SES仅用于电子邮件。

For SNS, the user should be subscribed to a topic and will receive updates from this topic when its updated. 对于SNS,用户应订阅一个主题,并在该主题更新时收到该主题的更新。 So, with SNS, he would need to confirm hist subscription to receive emails from the topic. 因此,使用SNS,他需要确认历史订阅才能接收来自该主题的电子邮件。 In SES, the user can receive transactional or promotional emails, which is your use case. 在SES中,用户可以接收交易或促销电子邮件,这就是您的用例。

A good approach would be using AWS Lambda to send the user a confirmation email with SES when he registers. 一个好的方法是使用AWS Lambda在用户注册时向用户发送带有SES的确认电子邮件。

To send emails using SES without asking the user to register, first you need to create a support ticket to AWS to increase use limits. 要使用SES发送电子邮件而不要求用户注册,首先需要创建AWS的支持凭单以增加使用限制。 Then you will only need to register the sender email. 然后,您只需要注册发件人电子邮件。

After that, create a AWS Lambda function and add a role that allows it to send emails with SES and here is a sample code to send email using SES and Lambda with node.js: 之后,创建一个AWS Lambda函数并添加一个角色,使其可以使用SES发送电子邮件,这是使用SES和Lambda和node.js发送电子邮件的示例代码:

var AWS = require('aws-sdk');

exports.handler = (event, context, callback) => {

    var ses = new AWS.SES({
        apiVersion: '2010-12-01'
    });

    var email = event['email'];
    var email_text = '<body><h5>Hello, World!</h5></body>';

    ses.sendEmail({
            Source: 'My Email <myemail@example.com>',
            Destination: {
                ToAddresses: [email]
            },
            Message: {
                Body: {
                    Html: {
                        Data: email_text
                    },
                    Text: {
                        Data: email_text
                    }
                },
                Subject: {
                    Data: 'Confirmation'
                }
            }

        }, function (err, data) {
            if (err) {
                callback(null, err);
            } else {
                callback(null, 'ok');
            }

        });
}

If later you need to send SNS for updates of any sort, then you should have the user subscribed to an SNS topic and use that service. 如果以后需要发送SNS进行各种更新,则应让用户订阅SNS主题并使用该服务。

It depends on the amount of emails you will be sending. 这取决于您将发送的电子邮件数量。 If there are lots of emails then it would be best to put those emails onto an SQS queue for processing. 如果有很多电子邮件,那么最好将这些电子邮件放在SQS队列中进行处理。 A worker can then consume from the queue and use SES to send the email messages to the users. 然后,工作人员可以从队列中消费并使用SES将电子邮件发送给用户。

If you only have a few emails to send and it's not enough that affects performance then you can send the emails directly from your application using SES. 如果仅发送几封电子邮件,而这不足以影响性能,则可以使用SES直接从应用程序发送电子邮件。

You are not required to subscribe a user's phone number to an SNS topic to be able to send SMS messages to that number [1]. 您无需为SNS主题订阅用户的电话号码即可向该号码发送SMS消息[1]。 So when the time comes that you want to also send a SMS message upon user registration you just modify your SQS queue processor (or application) to also send the SMS message to the user. 因此,当您希望在用户注册时也发送SMS消息的时候到了,您只需修改SQS队列处理器(或应用程序)以将SMS消息也发送给用户。

[1] http://docs.aws.amazon.com/sns/latest/dg/SMSMessages.html [1] http://docs.aws.amazon.com/sns/latest/dg/SMSMessages.html

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

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