Global Constant
Steve Nay's ramblings

Programming SQS with Python and Boto

In my last post, I left out a few details needed for Lab 4. One of those is Amazon SQS: Simple Queue Service.

You’ll notice in the comment function of simpledb.py that there is an invocation of funcs.addCommentToQueue(). I won’t show that function here, but I’ll give you an example using a test queue. The analogous function here is called addMessageToQueue().

Reading messages from SQS is pretty simple too. The second function, readMessageFromQueue(), gets all the messages currently in the queue and prints them out.

If you run this a few times, you’ll notice some interesting behaviors:

These limitations are just fine for our system, because we’re using them mainly to handle batch tasks (image processing). You probably won’t run into trouble with them, but you need to be aware of and handle these cases in your code.

Here is the supporting code for the above examples:

When you actually implement Lab 4, you will use a daemon. I will write more about that later. Basically, it will entail using a while loop and reading one message at a time, not in bulk like this.

Here is a good tutorial with a few more details than I have gone into here: An Introduction to boto’s SQS interface.