Skip to main content

Transparently stores oversize SNS messages in S3 and retrieves them when receiving messages using SQS.

Project description

boto3-oversize

Messages published using Amazon SNS have a maximum size of 256KiB, which can be a limitation for certain use cases. AWS provides an extended client library for Java that transparently uploads messages exceeding this threshold to S3 and restores them when the messages are received. This Python package provides the same functionality for boto3.

Installation

  1. Create an Amazon S3 bucket that will store message payloads that exceed the maximum size.
    • While the Java library deletes payloads from S3 when they are retrieved, this is not appropriate when there are multiple subscribers to the topic. Instead, apply a S3 lifecycle configuration to expire the message payloads after a reasonable length of time, e.g., 14 days.
  2. Install this package, e.g., pip install boto3-oversize.
  3. Define the OVERSIZE_PAYLOAD_BUCKET_NAME environment variable as the name of the bucket you created; ensure your AWS access credentials have permission to call PutObject and GetObject in the root of the bucket.

Usage

The library provides replacement implementations of the core boto3 entry points that transparently apply the necessary changes to the SNS and SQS clients, both for the low-level client and service resource. Simply reference boto3_oversize instead of boto3.

Low-level client example

import boto3_oversize

sns_client = boto3_oversize.client('sns')
response = sns_client.create_topic(Name='example-large-payload-topic')
sns_client.publish(TopicArn=response['TopicArn'], Message='example-message')

Service resource example

import boto3_oversize

sqs_client = boto3_oversize.resource('sqs')
queue = sqs_client.create_queue(QueueName='example-large-payload-queue')
messages = queue.receive_messages()

Implementation

Calls to publish messages are intercepted and the message body sized check against the limit, reduced by a small percentage to consider SNS message envelope overhead if raw message delivery is not enabled. If the message exceeds this threshold, it is uploaded to an S3 bucket and the SNS message replaced with the object ARN.

When receiving messages, the SQS client checks if the entire message body appears to be an S3 object ARN. If it is, the object is retrieved from S3 and returned to the caller as the message body.

Project details


Download files

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

Source Distribution

boto3_oversize-0.1.4.tar.gz (4.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

boto3_oversize-0.1.4-py3-none-any.whl (6.3 kB view details)

Uploaded Python 3

File details

Details for the file boto3_oversize-0.1.4.tar.gz.

File metadata

  • Download URL: boto3_oversize-0.1.4.tar.gz
  • Upload date:
  • Size: 4.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.17

File hashes

Hashes for boto3_oversize-0.1.4.tar.gz
Algorithm Hash digest
SHA256 85b170b4cce391a524012754125a40b5735a0b7523986e961ff511ccdb109ace
MD5 a6c721b2c3899d06f92b07cf60d69502
BLAKE2b-256 5ae9815a16072245cd3c6d0065f24f614cb33deab711d6c5466279de6ab077f7

See more details on using hashes here.

File details

Details for the file boto3_oversize-0.1.4-py3-none-any.whl.

File metadata

  • Download URL: boto3_oversize-0.1.4-py3-none-any.whl
  • Upload date:
  • Size: 6.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.17

File hashes

Hashes for boto3_oversize-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 8fc02c35935fd8131a1a963fbc1ad6410ead072f0220a46cea0ab4bfe2d2d188
MD5 83f4b31b235b5e201d1490a4f25d8316
BLAKE2b-256 6fdc17d8720da7b6f816e052fd7d3ec59d0bd363f010ceb1f4c2a3160686ddad

See more details on using hashes here.

Supported by

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