Skip to main content

A simple Python SQS listener

Project description

This package takes care of the boilerplate involved in creating an SQS listening agent.

Installation

pip install pySqsListener

Usage

Using the package is very straightforward - just inherit from the SqsListener class and implement the
handle_message() method.

Here is a basic code sample:

Standard Listener
from sqs_listener import SqsListener
class MyListener(SqsListener):
    def handle_message(self, body, attributes, messages_attributes):
        run_my_function(body['param1'], body['param2']

listener = MyListener('my-message-queue', 'my-error-queue')
listener.listen()

Error Listener

from sqs_listener import SqsListener
class MyErrorListener(SqsListener):
    def handle_message(self, body, attributes, messages_attributes):
        save_to_log(body['exception_type'], body['error_message']

error_listener = MyErrorListener('my-error-queue')
error_listener.listen()

Notes

  • The environment variable AWS_ACCOUNT_ID must be set, in addition to the environment having valid AWS credentials (via environment variables or a credentials file)

  • For both the main queue and the error queue, if the queue doesn’t exist (in the specified region), it will be created at runtime.

  • The error queue receives only two values in the message body: exception_type and error_message. Both are of type str

Upcoming Features

Create an issue with a suggestion for a feature, and I’ll see what I can do!

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

pySqsListener-0.2.2-py2.py3-none-any.whl (5.2 kB view hashes)

Uploaded Python 2 Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page