Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get SNS published message

I have an application that publishes messages via Amazon SNS to specified target. I need to get this message somehow using python. What is the simplest way to do it?

like image 941
user1590561 Avatar asked Nov 08 '16 12:11

user1590561


People also ask

How do I get my messages from SNS?

When a device subscribes to a topic, SNS will send a confirmation message to the device, and the user will have to confirm that they want to receive notifications, as shown below: After the user subscribes to the topic, they will receive SMS messages when you publish them to that topic.

What is publish message in SNS?

PDF. Sends a message to an Amazon SNS topic, a text message (SMS message) directly to a phone number, or a message to a mobile platform endpoint (when you specify the TargetArn ). If you send a message to a topic, Amazon SNS delivers the message to each endpoint that is subscribed to the topic.

Which AWS service is the best choice for publishing messages to subscribers?

Q: What is Amazon Simple Notification Service (Amazon SNS)? It provides developers with a highly scalable, flexible, and cost-effective capability to publish messages from an application and immediately deliver them to subscribers or other applications. It is designed to make web-scale computing easier for developers.


1 Answers

Amazon SNS does not directly allow messages to be retrieved. Rather, for a given topic in Amazon SNS, you configure subscribers. Subscribers can be, for example, an email address, an Amazon SQS queue, an HTTP endpoint or a few other options. See https://aws.amazon.com/sns/faqs/ (search for "How does Amazon SNS work") for an overview of how it works.

Using an SQS Queue

To receive a published from a python script, your best bet is to setup a new Amazon SQS queue for your script, and to subscribe the Queue to the SNS topic.

You can then poll the SQS queue to see if there are any messages in the queue.

This technique has the extra advantage that you won't miss any messages even if your python script is not running - they will be waiting there for you in the SQS queue.

boto is a great python library for interracting with Amazon, and this tutorial explains how to access an SQS queue.

Using an HTTP Endpoint

Alternatively, if you can deploy your Python script as a web application with an Http endpoint as an API, you can subscribe your Http endpoint to the SNS topic, and your endpoint will get invoked each time there is a new message. This techique is not recommended as if your script is offline, you will miss messages.

like image 104
Chris Simon Avatar answered Oct 17 '22 19:10

Chris Simon