Where S3 requests go. AWS uses virtual-hosted URLs on the regional endpoint, https://<bucket>.s3.<region>.amazonaws.com/<key>, or path-style for a bucket that can't be a hostname label: dots (the TLS wildcard certificate doesn't match those) and legacy uppercase names.

opts.endpoint points at an S3-compatible store (Cloudflare R2, MinIO, ...), which defaults to path-style: <endpoint>/<bucket>/<key>. Pass path-style: false for https://<bucket>.<endpoint host>/<key>, or path-style: true to force path-style on AWS.

A bucket goes into a URL, so resolve checks it with ::aws::core/check-bucket and a bad name is an Err before anything is signed.

Functions

base-url

fn (resolved: Map): Str

The S3 service URL (no trailing slash): resolved.endpoint, else https://s3.<region>.amazonaws.com.

Example

::aws::s3::api/base-url({region: "eu-west-1"})  // "https://s3.eu-west-1.amazonaws.com"

body-text

fn (body: Any): Str

A response body as a Str, decoding Bytes.

Example

::aws::s3::api/body-text(Bytes("<Name>my-bucket</Name>"))  // "<Name>my-bucket</Name>"

bucket-url

fn (bucket: Str, resolved: Map): Str

The URL of a bucket (no trailing slash) for resolved settings: see the namespace doc for the forms.

Example

::aws::s3::api/bucket-url("my-bucket", {region: "us-east-1"})  // "https://my-bucket.s3.us-east-1.amazonaws.com"
::aws::s3::api/bucket-url("my-bucket", {region: "auto", endpoint: "https://abc.r2.cloudflarestorage.com"})  // "https://abc.r2.cloudflarestorage.com/my-bucket"

decode-listed

fn (value: Str?): Str?

Decode a value from a listing made with encoding-type=url: + is a space and %XX an escape. Null stays null.

Example

::aws::s3::api/decode-listed("a+b%2Fc")  // "a b/c"
::aws::s3::api/decode-listed(null)  // null

object-url

fn (bucket: Str, key: Str, resolved: Map): Str

The URL of an object: bucket-url plus the key with each path segment encoded. / in the key stays a path separator.

Example

::aws::s3::api/object-url("my-bucket", "a b/c.txt", {region: "us-east-1"})  // "https://my-bucket.s3.us-east-1.amazonaws.com/a%20b/c.txt"

resolve

fn (opts: Map, bucket: Str): Map
fn (opts: Map, bucket: Str, other-bucket: Str): Map

::aws::core/resolve(opts), or an Err when a bucket isn't a valid name. Credentials in opts are masked first, whatever else is wrong.

Example

resolved ::aws::s3::api/resolve({region: "eu-west-1"}, "my-bucket")
resolved.region

// A bad bucket name is an Err before anything is signed
is-err(::aws::s3::api/resolve({}, "a..b"))