I have two way SMS setup with Pinpoint where the incoming SMS gets sent to an SNS Topic. I'd like to re-use this SNS topic for other phone numbers that are using two way. However, the subscribers to that topic will need to only see messages for the phone number that that particular subscriber is concerned with.
I know about subscription filter policies. However, the incoming SMS doesn't have a "Message Attributes" key and I haven't seen a way I can promote the "to" phone number or "keyword" to the message attribute so I can filter on it.
Is there a way to parse the body of the message to create the filter for a subscription?
There are no properties of a two way message that are promoted to be filtered on. I ended up sending the message to a lambda that promotes the properties I needed and re-published the message to another topic. I then had subscription filters subscribed to that topic.
Related
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)
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.
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
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
I am sending many messages but the subscribers change very often (per message), how can can i choose my specific subscribers on every message? the number of possibilities is too much to create topic to each combination.
You can't. A message is delivered to all subscribers of the SNS topic.
Once you subscribe an endpoint to a topic and the subscription is
confirmed, the endpoint will receive all messages published to that
topic. Source
You can manage the endpoints yourself on the back end. You then publish to an individual endpoint. For large groups you will have to build in flood protection.