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 and timeout configuration
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;
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_objects
processes in batches of 1000 (due to AWS S3 limitations)- Stream processing enables efficient handling of large numbers of objects