Question

I am getting my head around using SNS to send a message from one server to another. I want to create a message to send to the other server using Python and Boto so I was wondering if someone could look at this code designed to send the message "scraped":

import boto
sns = boto.connect_sns()

# Create Topic
t = sns.create_topic("scraped")
t
{u'CreateTopicResponse': {u'ResponseMetadata': {u'RequestId': u''}, u'CreateTopicResult': {u'TopicArn': u'arn:aws:sns:us-east-1:your-account-id:Test'}}}

Then on the other hand I want some code to check for this message on the second server, so I had something like this:

import boto
sns = boto.connect_sns()

# Read Topics
sns.get_all_topics()
{u'ListTopicsResponse': {u'ResponseMetadata': {u'RequestId': u''}, u'ListTopicsResult': {u'Topics': [{u'TopicArn': u'arn:aws:sns:us-east-1:your-account-id:Test'}], u'NextToken': None}}}

My first question is, have I got the right end of the stick? This is an entirely new concept to me and I'm having a hard time getting my head around it.

My second question is in order to check would I just run a cronjob on the python checking script every 5mins or so?

Was it helpful?

Solution

My first question is, have I got the right end of the stick?

I don't think so.

Imagine that SNS is just a bulletin board. Say you've posted a piece of paper to this bulletin board that says "Write your name on at the top of this paper if you want to sign up for piano lessons." This is the "topic."

You then add, "Write your name on the reverse side of this paper if you're a piano teacher looking for students. Also make a note of how you want to be notified when we find a new student: email, text message, or carrier pigeon." Teachers who add their name are creating a "subscription" to the topic.

When a student writes his name (publishes to the topic), every teacher is then simultaneously notified, via their preferred method, that there's been a new sign-up. It's up to each teacher to decide what to do with this information.

The code snippets that you have above are doing the first half of this. You're creating a topic and then viewing the topics. For it to do anything, you have to publish a message to the topic. I have some example code on my blog where I'm using Python's logging module to publish log messages to an SNS topic. That might give you a better understanding of a real-world use case.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top