Sending custom SNS notifications to only selected endpoints- using lambda - amazon-web-services

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)

Related

Amazon SES using Message Id

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).

aws calling lambda on cloudwatch alarm - Only email lists for this account are available

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.

Can I publish to a specific subscription in a SNS topic?

When I publish to a topic it hits ALL subscribers ALWAYS?
I have a topic with several subscriptions, sometimes I want to publish a message to just one of those subscriptions.
Is there a way to do this or do I need to create another topic and have the subscription in 2 topics? In that case I'm bugging the user (assuming this use case is to message users) twice right?
Yes -- when a message is sent to an Amazon SNS topic, all subscribers receive the message.
If you wish to contact a specific subscriber, your code will have to contact them directly (eg via email).
Amazon SNS also has the ability to send an SMS message to one or more recipients without using an SNS Topic. So, if your desired recipients are on SMS, this is a simple task.

Amazon-SNS. Limit delivery to SMS protocol while publishing

We are using Amazon SNS to sent SMS to customers through API(PHP). The topic may have email subscriptions as well as SMS subscriptions. I.e While creating a subscription,protocol may be email/sms. But we want to sent only SMS while publishing the messages. Email subscriptions should not receive any message. How to archive this?
This is not possible. All subscribers to the topic will be sent the message.
You can provide different versions of messages for different types of subscriptions (eg SMS vs email), but you cannot control which type of subscriber receives a message.
Some alternatives:
Maintain separate topics for situations where you wish to send a notification only to a subset of subscribers
Use Amazon Pinpoint to specifically target mobile users with notification campaigns

AWS SNS Mobile Push based on user notification preferences

I'm working SNS Push notifications into an app that I'm building, and I'm wondering how to handle user notification settings? What I don't understand is if SNS provides a way to manage a user who wants to receive notification type "A", but not type "B". A more real-world correlation is managing a Facebook user who wants notifications for comments, but not likes. Does SNS provide an easy way to manage this?
I can manage it myself through my own servers/databases, but this seems like something that SNS should be able to do.
I would suggest each notification type is a different SNS topic. That way the user can control each topic he is subscribed too. That puts more work for you in your app but this way you get to your designed goal of allowing each user to subscribe to each a different type of notification.
Topics are free but SNS messages sent are charged.
FREE TIER: Each month, Amazon SNS customers receive 1,000,000 Amazon SNS Requests, 100,000 HTTP notifications, 1,000 email notifications and 100 SMS notifications for free.
Cost calculator: http://calculator.s3.amazonaws.com/index.html
SNS Pricing Details: https://aws.amazon.com/sns/pricing/
No. SNS does not provide a way to manage users to subscribe based on notification types
In fact there is no implicit notification type definitions. Although you can have that as part of your payload.
So you can either
Have different topics for different notification types and then attach subscribers based on which type of messages they are interested in
Have a type definition defined within the payload and then let the filtering happen at the subscribers. But keep in mind that this will be costly affair because all subscribers receive all notifications and you can soon exhaust your free limit. Also the subscribers will receive unnecessary load