aws_utils_sqs
A Rust library providing utilities for working with AWS Simple Queue Service (SQS).
Features
- Queue management (create, delete)
- Message operations (send, receive, delete)
- Batch operations for sending and deleting messages
- Builder patterns for complex operations
- Type-safe queue attribute configuration
- FIFO queue support
- Dead letter queue configuration
Installation
Add this to your Cargo.toml:
[]
= "0.1.0"
Client Creation Functions
The library provides three functions for creating SQS clients with different timeout configurations:
make_client_with_timeout_default(endpoint_url: Option<String>) -> Client
Creates an SQS client with default timeout settings optimized for typical SQS operations.
Default timeout values:
- Connect timeout: 3100 seconds
- Operation timeout: 60 seconds
- Operation attempt timeout: 55 seconds
- Read timeout: 50 seconds
make_client_with_timeout(...) -> Client
Creates an SQS client with custom timeout settings. Accepts:
endpoint_url: Optional custom endpoint URLconnect_timeout: Optional timeout for establishing connectionsoperation_timeout: Optional timeout for entire operationsoperation_attempt_timeout: Optional timeout for individual operation attemptsread_timeout: Optional timeout for reading responses
make_client(endpoint_url: Option<String>, timeout_config: Option<TimeoutConfig>, interceptor: Option<SharedInterceptor>) -> Client
Creates an SQS client with optional custom endpoint URL, timeout configuration, and interceptor (e.g. for logging). This is the most flexible option when you need fine-grained control over the client.
Usage
Creating a Client
use make_client_with_timeout_default;
async
Creating a Client with Custom Timeouts
use Duration;
use make_client_with_timeout;
async
Using TimeoutConfig
use ;
use make_client;
use Duration;
async
Logging AWS Communication
make_client accepts an optional [SharedInterceptor]. By passing an interceptor that
implements aws_sdk_sqs::config::Intercept, you can run custom logic — such as logging —
every time the client communicates with AWS.
The interceptor below logs each request, response, and operation result. It uses the
tracing crate, which is also what the AWS SDK uses
internally.
use make_client;
use ;
type BoxError = ;
;
# async
tracing does not emit anything until a subscriber is initialized. Set one up once in your
application (for example with tracing-subscriber) and control verbosity with RUST_LOG:
// Add `tracing-subscriber` to your dependencies.
fmt
.with_env_filter
.init;
Example output (RUST_LOG=info):
INFO SqsLoggingInterceptor: SQS -> AWS request method=POST uri=https://sqs.ap-northeast-1.amazonaws.com/
INFO SqsLoggingInterceptor: AWS -> SQS response status=200
INFO SqsLoggingInterceptor: SQS operation succeeded
Creating a Queue
use ;
// Create a standard queue
let attributes = new
.visibility_timeout?
.message_retention_period?
.build?;
let result = create_queue.await?;
println!;
// Create a FIFO queue with content-based deduplication
let attributes = new
.content_based_deduplication
.fifo_throughput_limit
.deduplication_scope
.build?;
let result = create_queue.await?;
Sending Messages
use ;
// Send a single message
let result = send_message.await?;
// Send messages in batch
let entries = new
.add_message
.add_message_with_delay
.add_fifo_message
.build?;
let result = send_message_batch.await?;
Receiving Messages
// Receive up to 10 messages with long polling
let result = receive_message.await?;
if let Some = result.messages
Deleting Messages
use DeleteMessageBatchEntriesBuilder;
// Delete a single message
delete_message.await?;
// Delete messages in batch
let entries = new
.add_message
.add_message
.build?;
let result = delete_message_batch.await?;
Working with Dead Letter Queues
use ;
// Configure a dead letter queue
let redrive_policy = new;
let attributes = new
.redrive_policy
.build?;
// Configure which queues can use this queue as a dead letter queue
let redrive_allow_policy = by_queue;
let attributes = new
.redrive_allow_policy
.build?;
Error Handling
The library uses a custom Error type that wraps AWS SDK errors and provides additional context:
use Error;
match create_queue.await
License
This project is licensed under either of
- Apache License, Version 2.0, (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.