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
- 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.
- Install this package, e.g.,
pip install boto3-oversize
. - Define the
OVERSIZE_PAYLOAD_BUCKET_NAME
environment variable as the name of the bucket you created; ensure your AWS access credentials have permission to callPutObject
andGetObject
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
Built Distribution
File details
Details for the file boto3_oversize-0.1.3.tar.gz
.
File metadata
- Download URL: boto3_oversize-0.1.3.tar.gz
- Upload date:
- Size: 5.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 931d4813f4d8a2dff7c4201035b8e5a944b598eff6dee09a51b43c7fcbac27ca |
|
MD5 | 3c3646b4f5ff3a23d39501d94716dc45 |
|
BLAKE2b-256 | fb0d92b701892d40eee78b9a9b474059264cd9648a0ae48905a8e9db39c84938 |
File details
Details for the file boto3_oversize-0.1.3-py3-none-any.whl
.
File metadata
- Download URL: boto3_oversize-0.1.3-py3-none-any.whl
- Upload date:
- Size: 6.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4facb6d918650dddcf11f812776e963ac1b65b13b31e390077eadbb8a58da2ad |
|
MD5 | 8c79dd3d5ab68d2dfbbf092ef72199d2 |
|
BLAKE2b-256 | b4bef174dae21be569d39d5b6013da43f8d1e9ca2dd388170ec589bb4a641de9 |