Python version of AWS SQS extended client
Project description
Amazon SQS Extended Client Library for Python
Implements the functionality of amazon-sqs-java-extended-client-lib in Python
The Amazon SQS Extended Client allows clients to manage Amazon SQS message payloads that exceed the 256 KB message size limit, up to a size of 2 GB. In the event of publishing such large messages, the client accomplishes this feat by storing the actual payload in a S3 bucket and by storing the reference of the stored object in the SQS queue. Similarly, the extended-client is also used for retrieving and dereferencing these references of message objects stored in S3. Thus, the library is used for the following purposes:
- Specify whether payloads are always stored in Amazon S3 or only when a payload's size exceeds 256 KB.
- Send a message that references a single message object stored in an Amazon S3 bucket.
- Get the corresponding payload object from an Amazon S3 bucket.
- Delete the corresponding payload object from an Amazon S3 bucket.
Message Attributes for the SQS Extended Client
The SQS Extended Client makes use of several additional message attributes which helps it to handle large message payloads. This section shall outline the various attributes present:
large_payload_support
: This consists of the S3 Bucket name that is responsible for storing large messagesalways_through_s3
: This decides if all the message should be serialized to the S3 bucket. If set toFalse
, messages smaller than256 KB
will not be serialized to the s3 bucket.use_legacy_attribute
: This message attribute is present in the header for a message structure and is important for consumers to understand the name of the key in the dictionary which contains the information of the large message payload. If True, then all published messages use the Legacy reserved message attribute (SQSLargePayloadSize
) instead of the current reserved message attribute (ExtendedPayloadSize
).
Global Variables used by the SQS Extended Client
MESSAGE_POINTER_CLASS
: The value held by this global variable, or byLEGACY_MESSAGE_POINTER_CLASS
, is critical to the functioning of the client as it holds the class name of the pointer that stored the original payload in a S3 bucket.MAX_ALLOWED_ATTRIBUTES
: The value held by this global variable denotes the constraint of having a maximum of 10 message attributes for each large message payload.S3_KEY_ATTRIBUTE_NAME
: The value held by this global variable denotes the S3 Key, if present, which would be used to store the large message payload.DEFAULT_MESSAGE_SIZE_THRESHOLD
: This states the threshold for the size of the messages in the S3 bucket and it cannot be less than 0 or more than 262144 (default value).RESERVED_ATTRIBUTE_NAME
: The value held by this global variable, or byLEGACY_RESERVED_ATTRIBUTE_NAME
, denotes the attribute name which will be reserved for the purpose of handling large message payloads.
Getting Started
- Sign up for AWS -- Before you begin, you need an AWS account. For more information about creating an AWS account, see create and activate aws account.
- Minimum requirements -- Python 3.x (or later) and pip
- Download -- Download the latest preview release or pick it up from pip:
pip install amazon-sqs-extended-client
Using the Extended Client
Ensure that the package has been imported in the file you want to run your code from, by doing:
Setting up the prerequisites for sending message payloads > 256 KB
import boto3
import sqs_extended_client
sqs_extended_client = boto3.client("sqs", region_name="us-east-1")
sqs_extended_client.large_payload_support = "BUCKET_NAME_HERE"
sqs_extended_client.use_legacy_attribute = False
# Creating a SQS Queue and extracting it's Queue URL
queue = sqs_extended_client.create_queue(
QueueName = "DemoPreparationQueue"
)
queue_url = sqs_extended_client.get_queue_url(
QueueName = "DemoPreparationQueue"
)['QueueUrl']
# Creating a S3 bucket using the S3 client
sqs_extended_client.s3_client.create_bucket(Bucket=sqs_extended_client.large_payload_support)
Enabling support for payloads > 256 KB
# Sending a large message
large_message = small_message * 300000 # Shall cross the limit of 256 KB
send_message_response = sqs_extended_client.send_message(
QueueUrl=queue_url,
MessageBody=large_message
)
assert send_message_response['ResponseMetadata']['HTTPStatusCode'] == 200
# Receiving the large message
receive_message_response = sqs_extended_client.receive_message(
QueueUrl=queue_url,
MessageAttributeNames=['All']
)
assert receive_message_response['Messages'][0]['Body'] == large_message
receipt_handle = receive_message_response['Messages'][0]['ReceiptHandle']
# Deleting the large message
# Set to True for deleting the payload from S3
sqs_extended_client.delete_payload_from_s3 = True
delete_message_response = sqs_extended_client.delete_message(
QueueUrl=queue_url,
ReceiptHandle=receipt_handle
)
assert delete_message_response['ResponseMetadata']['HTTPStatusCode'] == 200
# Deleting the queue
delete_queue_response = sqs_extended_client.delete_queue(
QueueUrl=queue_url
)
assert delete_queue_response['ResponseMetadata']['HTTPStatusCode'] == 200
Security
See CONTRIBUTING for more information.
License
This project is licensed under the Apache-2.0 License.
Project details
Release history Release notifications | RSS feed
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 amazon_sqs_extended_client-1.0.1.tar.gz
.
File metadata
- Download URL: amazon_sqs_extended_client-1.0.1.tar.gz
- Upload date:
- Size: 14.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9924e758cd463866b898f56e752e9e59ce1457b195cd5f5466dc6f37141730ce |
|
MD5 | 5ae67be2d709c74daf58aaa5796b3ac2 |
|
BLAKE2b-256 | b200eb98606fad39a59ab187854d9f22ac5f14c5233a75b0e890c4fd41345a75 |
File details
Details for the file amazon_sqs_extended_client-1.0.1-py3-none-any.whl
.
File metadata
- Download URL: amazon_sqs_extended_client-1.0.1-py3-none-any.whl
- Upload date:
- Size: 14.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2d349896917d92698d0a5abd3f84279791fdf7ba0fec2352427c2d9cdb3d0b1f |
|
MD5 | 0f6c5cd74648584ad474dee1ad92f2ad |
|
BLAKE2b-256 | 4130250e8400a111de93903740773164bc59bc201e30572d13b3d0b623d91de5 |