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?
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.
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.
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With