Skip to main content

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:

  1. Specify whether payloads are always stored in Amazon S3 or only when a payload's size exceeds 256 KB.
  2. Send a message that references a single message object stored in an Amazon S3 bucket.
  3. Get the corresponding payload object from an Amazon S3 bucket.
  4. 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:

  1. large_payload_support : This consists of the S3 Bucket name that is responsible for storing large messages
  2. always_through_s3: This decides if all the message should be serialized to the S3 bucket. If set to False, messages smaller than 256 KB will not be serialized to the s3 bucket.
  3. 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

  1. MESSAGE_POINTER_CLASS: The value held by this global variable, or by LEGACY_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.
  2. 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.
  3. 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.
  4. 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).
  5. RESERVED_ATTRIBUTE_NAME: The value held by this global variable, or by LEGACY_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.

Release files for amazon-sqs-extended-client 1.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for amazon-sqs-extended-client 1.0.1
File Size Uploaded
amazon_sqs_extended_client-1.0.1.tar.gz 14.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for amazon-sqs-extended-client 1.0.1
File Interpreter ABI Platform
amazon_sqs_extended_client-1.0.1-py3-none-any.whl Python 3 none any Details

Total release size: 29.3 kB

Release files / amazon_sqs_extended_client-1.0.1.tar.gz

Download URL amazon_sqs_extended_client-1.0.1.tar.gz
Size 14.6 kB
Tags Source
SHA-256 checksum
How to use checksums
9924e758cd463866b898f56e752e9e59ce1457b195cd5f5466dc6f37141730ce
BLAKE2b-256 checksum
How to use checksums
b200eb98606fad39a59ab187854d9f22ac5f14c5233a75b0e890c4fd41345a75
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.12.6

Release files / amazon_sqs_extended_client-1.0.1-py3-none-any.whl

Download URL amazon_sqs_extended_client-1.0.1-py3-none-any.whl
Size 14.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2d349896917d92698d0a5abd3f84279791fdf7ba0fec2352427c2d9cdb3d0b1f
BLAKE2b-256 checksum
How to use checksums
4130250e8400a111de93903740773164bc59bc201e30572d13b3d0b623d91de5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.12.6

Release history Release notifications | RSS feed

This release

1.0.1 This release

2 release files

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page