> ## Documentation Index
> Fetch the complete documentation index at: https://docs.bijection.com/llms.txt
> Use this file to discover all available pages before exploring further.

# S3 object versions

> Retain versioned S3 objects as Files on your app.

Mount the objects app to observe one versioned general-purpose S3 bucket
and a literal prefix. Its versions, Files and records live under the label you
pass as `data`: the public label or one declared label.

## Mount and bind

`objects({ data, provider, writer })` returns the app to place at a path of
your tree. Bind the bucket with `s3Bucket`, declare its credential with
`secret()`, and place them beside the mount.

```ts app.ts theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
import { app, label, secret } from "@bijectionhq/bijection";
import objects, { s3Bucket } from "@bijectionhq/app-objects";

const archive = label();
const key = secret();
const bucket = s3Bucket({ bucket: "example-archive", region: "us-east-1", prefix: "incoming/" }, key, archive);

export default app({ archive, key, bucket, store: objects({ data: archive, provider: bucket }) });
```

Set the credential to JSON with `accessKeyId` and `secretAccessKey`. For an
AWS session, also supply `sessionToken` and `expiresAtMs` as Unix milliseconds, and rotate it before expiry. Grant `s3:ListBucketVersions` on the
bucket with the installed prefix condition and `s3:GetObjectVersion` on
objects under that prefix.
[Amazon S3 ListObjectVersions](https://docs.aws.amazon.com/AmazonS3/latest/API/API_ListObjectVersions.html),
[Amazon S3 GetObject](https://docs.aws.amazon.com/AmazonS3/latest/API/API_GetObject.html).

```sh theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
bijection secret set key --from-file s3-reader.json
bijection mutate store.source.initialize '{"format": null, "heapBucket": null}'
```

`store.operator` is granted from code: `ctx.grant(store.operator, { to, under })` in one of your
mutations ([Grants](https://docs.bijection.com/access/grants.md)).

The mount declares its `operator` role, which clears `data`. Only the operator
calls `store.source.*`, `store.versions.list`, `store.inventory.*` and
`store.writes.*`. The mount's tables, stored Files, staged ranges, source
controls and continuations all live under `data`, and the receiver answers
under the same label. Every object-store binder (`s3Bucket`, `gcsBucket`,
`azureBlobContainer`, `adlsDirectory`) takes the label as its last argument.
Each mount of the app builds its own tables, so two mounts never share rows.
Budget the label's `queries`, `holds` and `staging` quota parts for retained
clock tasks, sends and File bytes.

## Publication and controls

The app retains one publication per key and version ID. It validates the
version ID and ETag on every range and commits the File, its version row and
the next listing cursor together. Files are at most 1 MiB, assembled from
version-checked ranges of at most 24 KiB. Larger objects receive a metadata row. Retained
versions stay with their mount. A new bucket or prefix needs its own mount.

The app stages unfinished ranges as private Files and retires them when
publication completes or the read is abandoned. The File owner accounts for
each staged part and the final File before writing it to storage. Staged
parts use the label's ordinary File quota, including its retirement horizon.

A turn lists up to eight one-entry pages and expires after ten minutes. It
recovers from the last committed cursor after failure. A rejected retained
version or a receiver scope change records a gap. Use `source.health`
to read the revision and gap instant. Pass the revision to `poll`, `pause`
and `resume`; a stale revision refuses `RevisionMoved`. `source.reset` also
takes the observed `gapAt` and restarts enumeration while preserving accepted
versions.

This is a repeated enumeration of versions still present in S3. Delete
markers, null versions and keys with control characters, empty interior
path segments, or dot segments are skipped. Keys beginning with a slash
are also skipped. Live listing records observations. For deletion by absence at an immutable
snapshot, select a [versioned inventory](https://docs.bijection.com/integrations/native-object-inventory.md).

The app bundle requires the bundled parser artifact. Configure `source.initialize`
to publish CSV or JSON records alongside retained Files.
[CSV and JSON object records](https://docs.bijection.com/integrations/native-object-records.md).

## Put an object

Pass a writer receiver as `writer`, with its own credential. For S3, give
the writer permission for `s3:PutObject` under the installed prefix. Bind it
at the same `data` label.

```ts theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
import objects, { s3Bucket, s3Writer } from "@bijectionhq/app-objects";

const writerKey = secret();
const writer = s3Writer({ bucket: "example-archive", region: "us-east-1", prefix: "exports/" }, writerKey, archive);
// in the tree: { writerKey, writer, store: objects({ data: archive, provider: bucket, writer }) }
```

The operator calls `store.writes.put` and `store.writes.get`. Send
`{ key: "export-827", command: { key: "exports/orders.csv", data } }`.
The first key is the command key: the same key with other inputs refuses
`KeyReused`. The command's key names the entire object path within the
installed literal prefix, up to 1,024 UTF-8 bytes. The driver sends up to
24 KiB of canonical base64-decoded bytes as one binary PUT. This operation
can replace the current object or create a new version. The app submits one
task that is sent at most once and advances no read cursor.

An acknowledged S3 HTTP 200 covers the full-object PutObject request and
can carry a provider version ID and ETag. The ETag is opaque. It does not
prove a digest, later visibility, or that concurrent writers left the
same version current. An error status records the provider reply.
A lost or ambiguous reply settles the task `Unknown`. The write status
reports these task refusals as `refused` and supplies the refusal value in
`refusal`.
[Amazon S3 PutObject](https://docs.aws.amazon.com/AmazonS3/latest/API/API_PutObject.html)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.