s3
Module[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;pub struct S3Amazon 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.
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?;Debug.use utopia_storage::s3::client::HttpClient;pub struct HttpClientThe 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.
Default.use utopia_storage::s3::client::Payload;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.
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 startDebug, From.use utopia_storage::s3::client::Request;pub struct RequestA request, as a Client sends it.
use utopia_storage::s3::client::Response;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;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;pub enum MethodAn HTTP method S3 requests use.
use utopia_storage::s3::client::TransportError;pub enum TransportErrorWhy a request got no response.
use utopia_storage::s3::client::Client;pub trait Client: Send + SyncSends HTTP requests. Implement it to route S3 traffic through a client of your own (a proxy, a test double).
s3::regions::aws
Own pageAmazon S3 regions.
pub const AF_SOUTH_1: &str = "af-south-1"Undocumented.
pub const AP_EAST_1: &str = "ap-east-1"Undocumented.
pub const AP_NORTHEAST_1: &str = "ap-northeast-1"Undocumented.
pub const AP_NORTHEAST_2: &str = "ap-northeast-2"Undocumented.
pub const AP_NORTHEAST_3: &str = "ap-northeast-3"Undocumented.
pub const AP_SOUTH_1: &str = "ap-south-1"Undocumented.
pub const AP_SOUTHEAST_1: &str = "ap-southeast-1"Undocumented.
pub const AP_SOUTHEAST_2: &str = "ap-southeast-2"Undocumented.
pub const CA_CENTRAL_1: &str = "ca-central-1"Undocumented.
pub const CN_NORTH_1: &str = "cn-north-1"Undocumented.
pub const CN_NORTH_4: &str = "cn-north-4"Undocumented.
pub const CN_NORTHWEST_1: &str = "cn-northwest-1"Undocumented.
pub const EU_CENTRAL_1: &str = "eu-central-1"Undocumented.
pub const EU_NORTH_1: &str = "eu-north-1"Undocumented.
pub const EU_SOUTH_1: &str = "eu-south-1"Undocumented.
pub const EU_WEST_1: &str = "eu-west-1"Undocumented.
pub const EU_WEST_2: &str = "eu-west-2"Undocumented.
pub const EU_WEST_3: &str = "eu-west-3"Undocumented.
pub const ME_SOUTH_1: &str = "me-south-1"Undocumented.
pub const SA_EAST_1: &str = "eu-north-1"Undocumented.
pub const US_EAST_1: &str = "us-east-1"Undocumented.
pub const US_EAST_2: &str = "us-east-2"Undocumented.
pub const US_GOV_EAST_1: &str = "us-gov-east-1"Undocumented.
pub const US_GOV_WEST_1: &str = "us-gov-west-1"Undocumented.
pub const US_WEST_1: &str = "us-west-1"Undocumented.
pub const US_WEST_2: &str = "us-west-2"Undocumented.
s3::regions::backblaze
Own pageBackblaze B2 clusters.
pub const EU_CENTRAL_003: &str = "eu-central-003"Undocumented.
pub const US_WEST_000: &str = "us-west-000"Undocumented.
pub const US_WEST_001: &str = "us-west-001"Undocumented.
pub const US_WEST_002: &str = "us-west-002"Undocumented.
pub const US_WEST_004: &str = "us-west-004"Undocumented.
s3::regions::do_spaces
Own pageDigitalOcean Spaces regions.
pub const AMS3: &str = "AMS3"Undocumented.
pub const FRA1: &str = "fra1"Undocumented.
pub const NYC3: &str = "nyc3"Undocumented.
pub const SFO2: &str = "sfo2"Undocumented.
pub const SFO3: &str = "sfo3"Undocumented.
pub const SGP1: &str = "sgp1"Undocumented.
s3::regions::linode
Own pageLinode Object Storage regions.
pub const AP_SOUTH_1: &str = "ap-south-1"Undocumented.
pub const EU_CENTRAL_1: &str = "eu-central-1"Undocumented.
pub const US_EAST_1: &str = "us-east-1"Undocumented.
pub const US_SOUTHEAST_1: &str = "us-southeast-1"Undocumented.
s3::regions::wasabi
Own pageWasabi regions.
pub const AP_NORTHEAST_1: &str = "ap-northeast-1"Undocumented.
pub const AP_NORTHEAST_2: &str = "ap-northeast-2"Undocumented.
pub const EU_CENTRAL_1: &str = "eu-central-1"Undocumented.
pub const EU_CENTRAL_2: &str = "eu-central-2"Undocumented.
pub const EU_WEST_1: &str = "eu-west-1"Undocumented.
pub const EU_WEST_2: &str = "eu-west-2"Undocumented.
pub const US_CENTRAL_1: &str = "us-central-1"Undocumented.
pub const US_EAST_1: &str = "us-east-1"Undocumented.
pub const US_EAST_2: &str = "us-east-2"Undocumented.
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;pub struct RetryStrategyRetries 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.
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);Default, Debug.s3::uri
Own pageURLs as the PSR-7 Uri S3 builds its requests with normalizes them.