AWS S3 Utilities
A utility crate for AWS S3 client operations.
Features
Client Setup
make_client_with_timeout_default- Create an S3 client with default timeout settingsmake_client_with_timeout- Create an S3 client with custom timeout settingsmake_client- Create an S3 client with optional endpoint URL, timeout configuration, and interceptor (e.g. for logging)
Bucket Operations
bucket::create_bucket- Create a new S3 bucketbucket::list_stream- Stream buckets with prefix filteringbucket::list_all- List all buckets matching a prefixbucket::delete_bucket- Delete a bucket and all its contentsbucket::delete_buckets- Delete multiple buckets matching a prefix
Object Operations
object::list_stream- Stream objects from an S3 bucket with optional prefixobject::list_all- Retrieve all objects from an S3 bucket at onceobject::get_object- Retrieve an objectobject::is_exists- Check if an object existsobject::get_object_string- Retrieve object content as a stringobject::get_object_buf_reader- Get object as a BufferedReaderobject::put_object- Upload an objectobject::put_object_from_path- Upload an object from a file pathobject::delete_object- Delete a single objectobject::delete_objects- Batch delete objects matching a prefixobject::copy_object- Copy an object between bucketsobject::copy_objects_prefix- Copy multiple objects matching a prefix
Presigned URLs
presigned::put_presigned- Generate a presigned URL for uploadspresigned::get_presigned- Generate a presigned URL for downloadspresigned::presigned_url- Extract URL string from PresignedRequest
Usage Examples
use ;
// Create client with default timeout settings
let client = make_client_with_timeout_default.await;
// Bucket operations
create_bucket.await?;
let buckets = list_all.await?;
delete_bucket.await?;
// List objects
let objects = list_all.await?;
// Check if object exists
let exists = is_exists.await?;
// Get object
let object = get_object.await?;
let = get_object_string.await?;
// Upload object
put_object.await?;
// Upload from file
put_object_from_path.await?;
// Copy object
copy_object.await?;
// Copy objects with prefix
copy_objects_prefix.await?;
// Generate presigned URL
let presigned = get_presigned.await?;
let url = presigned_url;
// Batch delete objects with prefix
delete_objects.await?;
Timeout Configuration
use ;
use Duration;
// Use default timeout settings (recommended)
let client = make_client_with_timeout_default.await;
// Use custom timeout settings
let client = make_client_with_timeout.await;
// Use custom endpoint with default timeout settings
let client = make_client_with_timeout_default.await;
// Use legacy client without timeout configuration
let client = make_client.await;
// Use custom endpoint and no timeout (legacy)
let client = make_client.await;
Logging AWS Communication
make_client (and make_client_with_credentials) accepts an optional [SharedInterceptor].
By passing an interceptor that implements aws_sdk_s3::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 S3LoggingInterceptor: S3 -> AWS request method=GET uri=https://my-bucket.s3.ap-northeast-1.amazonaws.com/key.txt
INFO S3LoggingInterceptor: AWS -> S3 response status=200
INFO S3LoggingInterceptor: S3 operation succeeded
Error Handling
This crate provides an Error type that handles:
- AWS SDK errors
- Build errors
- ByteStream errors
- Presigning configuration errors
- I/O errors
- Validation errors
Helper methods for specific error checking:
is_no_such_key()- Check if object doesn't existis_no_such_bucket()- Check if bucket doesn't exist
Notes
delete_objectsprocesses in batches of 1000 (due to AWS S3 limitations)- Stream processing enables efficient handling of large numbers of objects