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.
Related
I send messages using SES api, set up topics in SNS for email delivery notifications.
I also use an SQS queue to put delivery notifications in there. Everything works for me, but I would like to have different queues for different email senders.
I assume that this can be done using a filter in Amazon SNS on a subscription that puts notifications in the SQS queue, but I can’t figure out how to do it and is it even possible for email delivery notifications, because I don’t send them, but Amazon itself, it’s unknown what are the attributes of the message sent to the SNS.
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 have several services, and each service creates an SNS topic which sends an email to me. e.g., whenever code deploy fails, I receive an email from an SNS topic, whenever codepipeline fails I receive an email from another SNS topic, whenever a specific lambda fails, I receive another SNS topic. None of the above failures is urgent, so it does not need to be taken care immediately.
How can I receive only one email report once a day for all the above failures? Maybe I should let the corresponding service trigger SQS instead of SNS and then once every day I pull all messages from SQS?
The option you mentioned with an SQS queue subscribed to the SNS topic is probably the best way to go. You can then use a scheduled Lambda function that runs once a day to poll the messages in the queue and send you an email with the aggregated information.
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 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.