slimta.cloudstorage.aws

This module defines the queue storage mechanism specific to the Amazon Web Services hosting service. It requires an account as well as the Simple Storage Service (S3) and optionally the Simple Queue Service (SQS) services.

For each queued message, the contents and metadata of the message are written to S3. Upon success, a reference to the S3 object is injected into SQS as a new message.

The SQS service is only necessary for alerting separate slimta processes that a new message has been queued. If reception and relaying are happening in the same process, SQS is unnecessary.

NOTE: This module uses the boto library to communicate with AWS. To avoid performance issues, you must use gevent monkey patching before using it!

from gevent import monkey; monkey.patch_all()

s3_conn = boto.connect_s3()
s3_bucket = s3_conn.get_bucket('slimta-queue')
s3 = SimpleStorageService(s3_bucket)

sqs_conn = boto.sqs.connect_to_region('us-west-2')
sqs_queue = sqs_conn.create_queue('slimta-queue')
sqs = SimpleQueueService(sqs_queue)

queue_storage = CloudStorage(s3, sqs)
class slimta.cloudstorage.aws.SimpleStorageService(bucket[, timeout=None[, prefix='']])

Bases: object

Instances of this class may be passed in to the CloudStorage constructor for the storage parameter to use S3 as the storage backend.

Keys added to the bucket are generated with prefix + str(uuid.uuid4()).

Parameters:
  • bucket (boto.s3.bucket.Bucket) – The S3 bucket object in which all message contents and metadata will be written. Each created S3 object will use a uuid string as its key.
  • timeout – Timeout, in seconds, before requests to S3 will fail and raise an exception.
  • prefix – The string prefixed to every key added to the bucket.
class slimta.cloudstorage.aws.SimpleQueueService(queue[, timeout=None[, poll_pause=1.0]])

Bases: object

Instances of this class may be passed in to the CloudStorage constructor for the message_queue parameter to use SQS as the message queue backend to alert other processes that a new message was stored.

Parameters:
  • queue (boto.sqs.queue.Queue) – The SQS queue object in which each new message corresponds to a new object in storage.
  • timeout – Timeout, in seconds, before requests to S3 will fail and raise an exception.
  • poll_pause – The time, in seconds, to idle between attempts to poll the queue for new messages.