guys! I have a task to create AWS lambda endpoint for resetting user's password. I have to send a new password to user's email. I have read a lot about SNS and SES and currently have no idea what service is better for my purpose. Will be glad to hear from you advice!
Here is my lambda code
const requestData = AdminResetPasswordDto.from(event.body);
const errors = await AdminResetPasswordDto.validate(requestData);
if (errors) {
return new BadRequestError({ message: "errors.invalid-request-params", errors })
}
const repo = new UsersRepo();
const entity = await repo.getOneByEmail(requestData.email);
if (!entity) {
return new BadRequestError({ message: 'errors.user-not-exists' })
}
// const newPass = generatePassword();
// sending newPass to user via SNS
// use SNS or SES ???
// https://docs.aws.amazon.com/sns/latest/dg/sns-email-notifications.html
const user = UserDto.fromEntity(entity);
const result = await repo.updateUserPassword(user.userId, user.userRole, newPass);
if (!result) {
return new BadRequestError({ message: 'errors.password-not-updated' })
}
return new ResponseSuccessNoBody();
SES is meant for sending high-volume e-mail efficiently and securely. Once you have verified that you are the owner of an e-mail address, you can send e-mails through SES to any other e-mail address without the recipient's consent. SES takes care of the engineering required to ensure the delivery of their e-mails.
SNS is meant as a channel publisher/subscriber service. In order to receive e-mails from SNS, the end-user must first subscribe and approve that subscription through e-mail before amazon delivers e-mails from the subscribed channel to that end-user. End-users can subscribe via e-mail, SMS, webhooks, and other means up to the user independent of the publisher.
On a practical level, we use SES to send our users e-mails about their content and we use SNS to send our developers notifications (via SMS and e-mail) when servers go down or have issues.
In short,
SNS
email messages
SMS
push notifications to mobile device
messages between services/apps
Clients have to subscribe, to receive above notifications
SES
email messages
No subscriptions required
SNS is used for “technical” notifications; delivery as e-mail is possible, but rather limited. First, you need to create dedicated subscriptions and provide the destination mail address at this point. Second, you can’t really “design” your messages, it will just be a blob of text. You should go with SES for messages where the recipient is determined at runtime and you want to have control over the message layout.
Related
I am trying to send personal message to particular user using webhook. I created webhook so i am getting personal message. But I am not able to send personal message to others personal chat. I don't want to use bot.
slack.setWebhook("Webhook");
slack.webhook({
channel: "D01KMUZ4E4S",
username: "webhookbot",
text: "This is posted to #general and comes from a bot named webhookbot."
}, function(err, response) {
console.log(response);
});
Slack Webhook URLs are tied to a particular channel, individual message, or group message. You need to create a new webhook in your workspace for each user you would like to send messages to.
I have created an E-Commerce IOS app with backend in nodejs (AWS Lambda). When a user signedIn/LoggedIn, the app subscribes a SNS Topic which I have created to send notifications and stores the push token and device ARN in DB.
Now I want to send push notification to all users who have subscribed that SNS Topic, when we added a new item to the store.
Currently, to send notification I am fetching all users from DB and loop through the users to get their push token and send notification to users one by one, which is very costly process, and the API took too much time.
Now I want to do is to hit the SNS topic from Lambda and pass the body of notification to that topic and that SNS topic will send notification to all users who have subscribed the Topic.
I have searched it but can't find any solution.
The code I have done to send notification is
await Promise.all(targetArns.map(async (item, index) => {
const publishNotificationParams = {
"TargetArn": item,
"Message": JSON.stringify({
"default": JSON.stringify({
"category" : title,
"alert" : {
"title" : title,
"body" : 'New product is launced',
"data" : product
},
"badge" : 1,
"sound" : "chime.aiff"
}),
"APNS_SANDBOX": JSON.stringify(params),
"APNS": JSON.stringify(params)
}),
"MessageStructure": "json"
};
var publishTextPromise = sns.publish(publishNotificationParams).promise();
publishTextPromise.then(
function(data) {
console.log(`Message ${publishNotificationParams.Message} sent to the topic ${publishNotificationParams.TargetArn}`);
}).catch(
function(err) {
console.error(err, err.stack);
});
}));
But for this I have to fetch every user from DB get their endpoint ARN and then send notification by iteration.
I want to call SNS topic pass the body of notification and SNS will send notification to every user that has subscribed that SNS topic.
I am doing this because I want to save the cost to fetch every users from DB and then send notification
This is how you could achieve that flow. I think you already have some parts of this implemented.
Create a topic that will be used to fan out the notification to all of your users: https://docs.aws.amazon.com/sns/latest/api/API_CreateTopic.html
Create platform application(s) for the different platforms your app is used on: https://docs.aws.amazon.com/sns/latest/api/API_CreatePlatformApplication.html
When a user signs up for your app, create a platform endpoint for the application corresponding to the user's platform: https://docs.aws.amazon.com/sns/latest/api/API_CreatePlatformEndpoint.html
3.1. If you want to be able to target this user directly, also store this ARN somewhere for direct publishes (as you are doing now).
Now also create a subscription for the topic created in step 1 to the endpoint ARN: https://docs.aws.amazon.com/sns/latest/api/API_Subscribe.html
Publish to the topic created during step 1: https://docs.aws.amazon.com/sns/latest/api/API_Publish.html
SNS will automatically fan out the message to all subscribers (all of your users), so each of them will receive a notification without you iterating over each user.
I am trying to send email to my other email from amazon SES verified email, but the programs gives an error that email address in to field is not verified. I am making a web app which allows user to log in using AWS Cognito so I dont have their email addresses in database. I need to send email to them on an event(I cannot use SNS because I need to send emails to selective persons which I have figured out.) So my questions are:
a)Do we need to verify SES email of the recipient also?
b)If yes, how can we use the cognito identity pool to verify their email addresses for SES.
code:
var aws = require("aws-sdk");
aws.config.update({
region: "us-west-2",
});
var ses = new aws.SES({"accessKeyId": "Mykey", "secretAccessKey":"YY","region":"us-west-2"})
var to = ['xyz#gmail.com']
var from='abc#gmail.com'
ses.sendEmail( {
Source: from,
Destination: { ToAddresses: to },
Message: {
Subject:{
Data:"Sending emails through SES"
},
Body: {
Text: {
Data: 'Stop your messing around',
}
}
}
}
, function(err, data) {
if(err) throw err
console.log('Email sent:');
console.log(data);
}
Error:
MessageRejected: Email address is not verified. The following identities failed the check in region US-WEST-2: xyz#gmail.com
If you're testing this inside your SES sandbox, you need to manually verify the recipient email addresses before it will allow you to send.
This step isn't required after leaving the sandbox, but it's a reasonable default safety setting when testing email-related functionality during development and not wanting bogus emails to go our for real.
Amazon SES Email Sending Errors (relevant portion in bold):
Email address is not verified. The following identities failed the
check in region : , , —You
are trying to send email from an email address or domain that you have
not verified with Amazon SES. This error could apply to the "From",
"Source", "Sender", or "Return-Path" address. If your account is still
in the sandbox, you also must verify every recipient email address
An easier way to test your email sending in AWS without needing to send actual emails would be to use their mailbox simulator:
The Amazon SES mailbox simulator is a set of test email addresses.
Each email address represents a specific scenario. You can send emails
to the mailbox simulator when you want to:
Test your application without having to create test "To" addresses.
How do we mention the conversation id in the botframework webchat instead of it being randomly generated? We can currently mention the userid and username for the webchat but could not have the conversation id mentioned.
For more information on this subject, check out the guide: Send proactive messages.
To be able to send an ad hoc message to a user, the bot must first collect and save information about the user from the current conversation. The address property of the message includes all of the information that the bot will need to send an ad hoc message to the user later.
bot.dialog('/', function(session, args) {
var savedAddress = session.message.address;
// (Save this information somewhere that it can be accessed later, such as in a database.)
var message = 'Hello user, good to meet you! I now know your address and can send you notifications in the future.';
session.send(message);
});
After the bot has collected information about the user, it can send an ad hoc proactive message to the user at any time. To do so, it simply retrieves the user data that it stored previously, constructs the message, and sends it.
function sendProactiveMessage(address) {
var msg = new builder.Message().address(address);
msg.text('Hello, this is a notification');
msg.textLocale('en-US');
bot.send(msg);
}
I am implementing AWS SNS with AWS SES.
I am registering notification that calls my http endpoint handler and i am receiving perfect notification object. But along with notification identity i want to send my extra payloads that can be received when registered endpoints called. I am doing it in nodeJS
here is the snippet of registering notification
var params = {
Identity: 'myemail#mydomain.com', /* required */
NotificationType: 'Bounce', //["Delivery","Bounce","Complaint"], /* required */
SnsTopic: 'arn:aws-arnstring'
};
ses.setIdentityNotificationTopic(params, function(err, data) {
if (err) console.log(err, err.stack); // an error occurred
else console.log(data); // successful response
});
is there anyway to send extra params like Identity and NotificationType ?
thanks in advance
There does not appear to b a mechanism for adding metadata, however... the notification should contain source inside the mail object, which looks like it would be the sending email address.
Arguably, there's no need for additional metadata, because there's also the messageId provided with the notifications. This is the same identifier you got back when you submitted the message.
If you saved the metadata locally (or even in simpledb, dynamodb, rds, or even S3) under that ID when the message was submitted, you'd be able to look it up again. If you don't save something with each message you send, then you don't have a way to "close the loop" and track the fact that you've received a notification of bounce, complaint, or delivery of each message to each recipient from SES.
http://docs.aws.amazon.com/ses/latest/DeveloperGuide/notification-contents.html
It isn't currently possible to send extra parameters along with the notification. You should submit this feature request to the Amazon SES team, either via the Amazon SES forums or through AWS Developer Support.