Im using AWS Lambda for sending emails by Amazon SES.
Each time that the request send_email succeeds I got the message id like confirmation.
But now, I want to use somehow this messageId. For example to know if this message concretelly get delivered or bounced.
CloudWatch offers me metrics, with the number of delivered or bounced messages but I want to look throught each one.
¿Is there any statement that allows to know the state of a message by id?
Due to the asynchronous nature of SMTP and how mails are being routed, you can't have this information immediately when sending an e-mail (via SES or otherwise).
However, AWS provides a feedback system which notifies an SNS topic when a message is delivered, bounced, or a complaint was received.
While the documentation is very detailed, the general idea is that you subscribe your own lambda(s) to the configured SNS topic(s) and you can then handle these events as you see fit (i.e. persist data on DynamoDB, call your unsubscribe API and so on).
Related
On AWS I'm trying to create a cloudwatch alarm that sends a notification to a sns topic that in turn triggers a lambda function that is subscribed to the topic, but have run into a bit of a snag in which my lambda is never triggered. I've followed several tutorials on how to do this, I've manually tested the sns -lambda connection and this is working as is attaching the notification trigger onto cloudwatch.
I've done this all through cloudformation.
I have also tried to configure it manually from the cloudwatch console and then noticed something strange. Underneath the Send a notification to select box as shown in the image below, there is a message which says Only email lists for this account are available. So I'm guessing from that, that somewhere in this account, there is a weird setting that needs to be changed?
Updated answer:
Is the CloudWatch alarm actually in the "Alarm" state? Can you add 2 more notifications to be triggered by the "OK" and "Insufficient data" state respectively?
by reading the original post, SNS should have the right permission to invoke the Lambda function.
previous answer:
That is a general message, it has nothing to do with your SNS topic settings. I reckon it's meant to say only emails opt-in to that SNS topic will get emails.
Q: How does Amazon SNS validate a subscription request to ensure that notifications will not be sent to users as spam?
As part of the subscription registration, Amazon SNS will ensure that notifications are only sent to valid, registered subscribers/end-points. To prevent spam and ensure that a subscriber end-point is really interested in receiving notifications from a particular topic, Amazon SNS requires an explicit opt-in from subscribers using a 2-part handshake:
i. When a user first calls the Subscribe API and subscribes an end-point, Amazon SNS will send a confirmation message to the specified end-point.
ii. On receiving the confirmation message at the end-point, the subscriber should confirm the subscription request by sending a valid response. Only then will Amazon SNS consider the subscription request to be valid. If there is no response to the challenge, Amazon SNS will not send any notifications to that end-point. The exact mechanism of confirming the subscription varies by the transport protocol selected:
For HTTP/HTTPS notifications, Amazon SNS will first POST the confirmation message (containing a token) to the specified URL. The application monitoring the URL will have to call the ConfirmSubscription API with the token included token.
For Email and Email-JSON notifications, Amazon SNS will send an email to the specified address containing an embedded link. The user will need to click on the embedded link to confirm the subscription request.
For SQS notifications, Amazon SNS will enqueue a challenge message containing a token to the specified queue. The application monitoring the queue will have to call the ConfirmSubscription API with the token.
Note: The explicit “opt-in” steps described above are not required for the specific case where you subscribe your Amazon SQS queue to your Amazon SNS topic – and both are “owned” by the same AWS account.
Let say I have 100 people who subscribed to a topic called :"remeinde_me_my_appointment" and I have lambda function that gives me a list of 5 people with their endpoints who should be reminded about their appointments tomorrow.
Now my question is, how does the communication between lambda and SNS should work?
All I want to do is to send 5 messages to 5 people who signed up to receive notifications and well I've magically got all their endpoints.
Am I sending them back to the topic again?! what do I do form here I'm confused? It looks like I've defined my own topic and subscription already but what's next?
This is not a good use-case for subscribing to an Amazon SNS topic.
When a message is sent to an SNS topic, all recipients receive the message. You can also use Amazon SNS Message Filtering to limit which subscribers receive a message, based on a message attribute.
However, based on your use-case, this is not a good way to send your messages. Your use-case would probably be better handled by sending individual messages to each person with customized information about their appointment, such as:
Dear Joe, this is a reminder of your appointment with Dr Smith at 10am tomorrow.
So, instead of sending a message to a Topic, use the Amazon SNS publish() command with an Endpoint ARN:
sns.publish(TargetArn=user_endpoint_arn, Message=msg)
To use the Publish action for sending a message to a mobile endpoint, such as an app on a Kindle device or mobile phone, you must specify the EndpointArn for the TargetArn parameter. The EndpointArn is returned when making a call with the CreatePlatformEndpoint action.
This is good for sending a message to a mobile application.
If, instead, you are merely sending an SMS message, then you can publish directly to the mobile number:
sns.publish(PhoneNumber='+16025551234', Message=msg)
I want to get the delivery status of the mails sent through Amazon SES by hitting an API and saving the response in my database. I know of Amazon SNS and sending notification through email, but could not find a solution for this. Is there a solution to this?
There is no polling mechanism in SES for delivery status.
The SNS delivery/status notifications that SES provides, which you have indicated you are familiar with, is the standard mechanism for this.
Enable these and then subscribe an SQS queue, or a Lambda function, or even an HTTPS endpoint from your app, to the designated SNS topic. It should be relatively simple using any of these mechanisms to code a solution to store the reports in the database as they are provided to you by SES.
We are using AWS SNS to send out email for Alarms .We receive the email with subject Newsletter/Marketing which we are trying to avoid.
Is there any way where we can configure the subject for SNS notification email in AWS console??
We receive the email with [the] subject [prefixed with] Newsletter/Marketing which we are trying to avoid
This does not sound like anything CloudWatch or SNS would be adding.
This sounds like something your email service or server is adding, after the mesage is received, in a misguided effort to be "helpful."
Examine the headers of the incoming mesage -- you may see evidence of this tampering. Or Send the email to a mailbox on a different mail service, such as Gmail (which I assume you are not using, since my CloudWatch alarms do not show this), and examine what you see in the message.
I have implemented SES in one of my application. Currently the I have implemented is that using SDK I wait for the success/failure response and take action based on the response. Now, I want to make is async so the process does not have to wait for the response and if any failure happen I should be able to see it and resend the email.
I have following questions.
I checked the CloudTrial does not support SendEmail or SendRawEmail then where can I see the status of an email whether its sent or not?
I read that SES makes the first attempt to send an email within few milliseconds. Does it retries if the first attempt was a failure or the SES was out of service?
Is there a better way of achieving what I want to achieve?
Can I see the SES queue anywhere?
Thanks
You can sign up to receive Bounces, Complaints and Delivery notifications via SNS. That's all you can do. You can't see the SES queue or get any other visibility into SES besides what the SNS notifications give you.
Amazon will make several attempts to deliver your e-mails to the recipients.
The big thing is that they will not give you the bounce notification until 12-24 hours later in my experience. This is due to them retrying to send the mail a few times, waiting for mail hosts to be available, etc.
If you use SES you should use their SNS system to check for bounces, complaints, and delivery notifications. That way you can handle the failed deliveries in a graceful manner.
Amazon's Doc here gives you some insight into how it works
http://docs.aws.amazon.com/ses/latest/DeveloperGuide/sending-email-with-ses.html