Rust

[S3]: Amazon S3 and S3-compatible object stores, and the HTTP client, retry strategy and region names it works with.

Contents

9 submodules, and what the module defines itself.

use utopia_storage::S3;
Rust
pub struct S3

Amazon S3 or an S3-compatible object store (MinIO, Google Cloud Storage, DigitalOcean Spaces, Backblaze, Linode, Wasabi...).

Every request is signed with AWS Signature V4 and carries an explicit Content-Length. Writes return the object's ETag; Device::create and Device::replace send If-None-Match and If-Match, which S3 checks in the same step as the write. Chunked uploads are multipart uploads. With a bucket name, copies on the same device run server side. The default client retries transient failures with RetryStrategy.

Rust
use utopia_storage::{Body, Device, S3};

let device = S3::new("uploads", "access-key", "secret-key", "http://minio:9000/bucket", "us-east-1")?;
let etag = device.write(&device.path("hello.txt"), Body::from("Hello World"), "text/plain").await?;
Compiles in CI; needs a running service to execute.
Also implements Debug.

s3::client

Own page

The HTTP client S3 sends its requests through.

use utopia_storage::s3::client::HttpClient;
Rust
pub struct HttpClient

The default client: HTTP/1.1 over plain TCP or TLS (the web PKI's roots), keeping connections alive, with no overall deadline. Request payloads go out chunk by chunk, and Client::stream hands the response body over as it arrives.

Also implements Default.
use utopia_storage::s3::client::Payload;
Rust
pub struct Payload(Contents)

The body of a [Request]: bytes in memory, or a seekable Body streamed from its start each time the request is sent, so a retry sends the same bytes and only one chunk of a large upload is in memory at a time.

Rust
use utopia_storage::Body;
use utopia_storage::s3::Payload;

let payload = Payload::from_body(Body::from("Hello World"));
assert_eq!(&payload.bytes().await?[..], b"Hello World");
assert_eq!(&payload.bytes().await?[..], b"Hello World"); // read again from the start
Also implements Debug, From.
use utopia_storage::s3::client::Request;
Rust
pub struct Request

A request, as a Client sends it.

use utopia_storage::s3::client::Response;
Rust
pub struct Response<B = Bytes>

A response, as a Client returns it: its body in memory (Bytes, from Client::send) or still to read (Body, from Client::stream).

use utopia_storage::s3::client::Retry;
Rust
pub struct Retry<C>

A client that retries what a RetryStrategy says to. Each attempt sends the request's Payload again from its start.

use utopia_storage::s3::client::Method;
Rust
pub enum Method

An HTTP method S3 requests use.

use utopia_storage::s3::client::TransportError;
Rust
pub enum TransportError

Why a request got no response.

use utopia_storage::s3::client::Client;
Rust
pub trait Client: Send + Sync

Sends HTTP requests. Implement it to route S3 traffic through a client of your own (a proxy, a test double).

Implemented byArcRetryHttpClient

s3::regions

Own page

Region names of the providers S3 has constructors for.

s3::regions::aws

Own page

Amazon S3 regions.

Rust
pub const AF_SOUTH_1: &str = "af-south-1"

Undocumented.

Rust
pub const AP_EAST_1: &str = "ap-east-1"

Undocumented.

Rust
pub const AP_NORTHEAST_1: &str = "ap-northeast-1"

Undocumented.

Rust
pub const AP_NORTHEAST_2: &str = "ap-northeast-2"

Undocumented.

Rust
pub const AP_NORTHEAST_3: &str = "ap-northeast-3"

Undocumented.

Rust
pub const AP_SOUTH_1: &str = "ap-south-1"

Undocumented.

Rust
pub const AP_SOUTHEAST_1: &str = "ap-southeast-1"

Undocumented.

Rust
pub const AP_SOUTHEAST_2: &str = "ap-southeast-2"

Undocumented.

Rust
pub const CA_CENTRAL_1: &str = "ca-central-1"

Undocumented.

Rust
pub const CN_NORTH_1: &str = "cn-north-1"

Undocumented.

Rust
pub const CN_NORTH_4: &str = "cn-north-4"

Undocumented.

Rust
pub const CN_NORTHWEST_1: &str = "cn-northwest-1"

Undocumented.

Rust
pub const EU_CENTRAL_1: &str = "eu-central-1"

Undocumented.

Rust
pub const EU_NORTH_1: &str = "eu-north-1"

Undocumented.

Rust
pub const EU_SOUTH_1: &str = "eu-south-1"

Undocumented.

Rust
pub const EU_WEST_1: &str = "eu-west-1"

Undocumented.

Rust
pub const EU_WEST_2: &str = "eu-west-2"

Undocumented.

Rust
pub const EU_WEST_3: &str = "eu-west-3"

Undocumented.

Rust
pub const ME_SOUTH_1: &str = "me-south-1"

Undocumented.

Rust
pub const SA_EAST_1: &str = "eu-north-1"

Undocumented.

Rust
pub const US_EAST_1: &str = "us-east-1"

Undocumented.

Rust
pub const US_EAST_2: &str = "us-east-2"

Undocumented.

Rust
pub const US_GOV_EAST_1: &str = "us-gov-east-1"

Undocumented.

Rust
pub const US_GOV_WEST_1: &str = "us-gov-west-1"

Undocumented.

Rust
pub const US_WEST_1: &str = "us-west-1"

Undocumented.

Rust
pub const US_WEST_2: &str = "us-west-2"

Undocumented.

s3::regions::backblaze

Own page

Backblaze B2 clusters.

Rust
pub const EU_CENTRAL_003: &str = "eu-central-003"

Undocumented.

Rust
pub const US_WEST_000: &str = "us-west-000"

Undocumented.

Rust
pub const US_WEST_001: &str = "us-west-001"

Undocumented.

Rust
pub const US_WEST_002: &str = "us-west-002"

Undocumented.

Rust
pub const US_WEST_004: &str = "us-west-004"

Undocumented.

s3::regions::do_spaces

Own page

DigitalOcean Spaces regions.

Rust
pub const AMS3: &str = "AMS3"

Undocumented.

Rust
pub const FRA1: &str = "fra1"

Undocumented.

Rust
pub const NYC3: &str = "nyc3"

Undocumented.

Rust
pub const SFO2: &str = "sfo2"

Undocumented.

Rust
pub const SFO3: &str = "sfo3"

Undocumented.

Rust
pub const SGP1: &str = "sgp1"

Undocumented.

s3::regions::linode

Own page

Linode Object Storage regions.

Rust
pub const AP_SOUTH_1: &str = "ap-south-1"

Undocumented.

Rust
pub const EU_CENTRAL_1: &str = "eu-central-1"

Undocumented.

Rust
pub const US_EAST_1: &str = "us-east-1"

Undocumented.

Rust
pub const US_SOUTHEAST_1: &str = "us-southeast-1"

Undocumented.

s3::regions::wasabi

Own page

Wasabi regions.

Rust
pub const AP_NORTHEAST_1: &str = "ap-northeast-1"

Undocumented.

Rust
pub const AP_NORTHEAST_2: &str = "ap-northeast-2"

Undocumented.

Rust
pub const EU_CENTRAL_1: &str = "eu-central-1"

Undocumented.

Rust
pub const EU_CENTRAL_2: &str = "eu-central-2"

Undocumented.

Rust
pub const EU_WEST_1: &str = "eu-west-1"

Undocumented.

Rust
pub const EU_WEST_2: &str = "eu-west-2"

Undocumented.

Rust
pub const US_CENTRAL_1: &str = "us-central-1"

Undocumented.

Rust
pub const US_EAST_1: &str = "us-east-1"

Undocumented.

Rust
pub const US_EAST_2: &str = "us-east-2"

Undocumented.

Rust
pub const US_WEST_1: &str = "us-west-1"

Undocumented.

s3::retry

Own page

[RetryStrategy]: which failed S3 requests are worth sending again.

use utopia_storage::s3::retry::RetryStrategy;
Rust
pub struct RetryStrategy

Retries transient S3 failures.

A rejected request (throttled, or never sent) is always retried. One that may have been applied (an internal error, a dropped or timed-out connection) is only retried when replaying it is harmless: not a POST other than CompleteMultipartUpload, and not a conditional write, whose condition the first attempt may already have changed. The XML error code wins over the HTTP status. Waits use exponential backoff with full jitter, or a numeric Retry-After.

Rust
use utopia_storage::s3::{Method, Request, Response, RetryStrategy};

let strategy = RetryStrategy::new(3, 0.5, 20.0).with_randomizer(|| 1.0);
let request = Request { method: Method::Put, url: "https://s3.example.com/a".into(), headers: vec![], body: Default::default() };
assert_eq!(strategy.delay(&request, 1, Some(&Response::new(503)), None), Some(0.5));
assert_eq!(strategy.delay(&request, 1, Some(&Response::new(404)), None), None);
Also implements Default, Debug.

s3::uri

Own page

URLs as the PSR-7 Uri S3 builds its requests with normalizes them.