Reputation: 3600
I have a web application where users can register to it.
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 ?
Are there any advantage over the two ?
Upvotes: 1
Views: 1993
Reputation: 3414
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. A worker can then consume from the queue and use SES to send the email messages to the users.
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.
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]. 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.
[1] http://docs.aws.amazon.com/sns/latest/dg/SMSMessages.html
Upvotes: 1
Reputation: 1952
SNS and SES can confuse the use cases sometimes. Like the names say, SNS is for notifications, that can be via email, push notifications, sms, and others, while SES is just for emails.
For SNS, the user should be subscribed to a topic and will receive updates from this topic when its updated. So, with SNS, he would need to confirm hist subscription to receive emails from the topic. In SES, the user can receive transactional or promotional emails, which is your use case.
A good approach would be using AWS Lambda to send the user a confirmation email with SES when he registers.
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. 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:
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 <[email protected]>',
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.
Upvotes: 1