adimona
adimona

Reputation: 109

Sending custom SNS notifications to only selected endpoints- using lambda

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?

Upvotes: 0

Views: 1376

Answers (1)

John Rotenstein
John Rotenstein

Reputation: 269091

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)

Upvotes: 2

Related Questions