> For the complete documentation index, see [llms.txt](https://docs.adiom.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.adiom.io/reference/connectors/s3.md). Agents can also search and read this documentation through its [MCP server](https://docs.adiom.io/~gitbook/mcp).

# S3

The S3 connector exports data from any Dsync source straight into an S3 bucket as JSON files, and imports JSON files from a bucket into any Dsync destination. It is open source and built into dsync/dsynct. Nothing is staged on local disk, and Amazon S3 or any S3-compatible store (MinIO, LocalStack) works.

Use it to archive collections and tables in S3, to hand data to tools that read JSON from a bucket, or to load JSON arrays produced elsewhere into a database. For CSV files on local disk, see the [File (CSV)](https://docs.adiom.io/reference/connectors/file.md) connector.

## Configuration

Give an `s3://` URL as the source or the destination. An optional key prefix follows the bucket name:

```
s3://bucket
s3://bucket/prefix
```

The connector copies data once, so run it with `--mode InitialSync`.

Connector options go directly after the `s3://` URL. `--region` is required.

| Option                                                      | Default        | Description                                                                                             |
| ----------------------------------------------------------- | -------------- | ------------------------------------------------------------------------------------------------------- |
| `--region`                                                  | none, required | AWS region of the bucket.                                                                               |
| `--prefix`                                                  | none           | Key prefix. If the URL also has a prefix, this one is appended to it.                                   |
| `--output-format`                                           | `json`         | File format. Only `json` is supported.                                                                  |
| `--pretty-json`                                             | `true`         | Indent the JSON in written files. Set `--pretty-json=false` for smaller files.                          |
| `--max-file-size`                                           | `10`           | Size in MB at which a namespace's buffer is written out as a file.                                      |
| `--max-total-memory`                                        | `100`          | Memory in MB for buffered and in-flight data. When it is full, the largest buffer is written out early. |
| `--profile`                                                 | none           | AWS shared config profile.                                                                              |
| `--access-key-id`, `--secret-access-key`, `--session-token` | none           | Static credentials. Used only when both the key ID and the secret are set.                              |
| `--endpoint`                                                | none           | Custom endpoint for S3-compatible services.                                                             |
| `--use-path-style`                                          | `false`        | Path-style addressing, usually needed for MinIO and LocalStack.                                         |

Without static credentials or `--profile`, the connector uses the standard AWS credential chain: environment variables, the `~/.aws` config, or an instance or pod role. The credentials need `s3:ListBucket`, `s3:GetObject` and `s3:PutObject` on the bucket.

## Object Layout

Each namespace gets its own folder under the prefix, with dots turned into folders: `shop.orders` becomes `<prefix>/shop/orders/`, and a DynamoDB table `table1` becomes `<prefix>/table1/`.

```
s3://bucket/prefix/
├── table1/
│   ├── .metadata.json
│   ├── 1763571203458129000.json
│   └── 1763571203912770000.json
└── table2/
    ├── .metadata.json
    └── 1763571204100453000.json
```

* Each data file is one JSON array of documents. A namespace is split across files of about `--max-file-size` each, named by the time they were written in Unix nanoseconds.
* `.metadata.json` maps each file name in the folder to its document count. Dsync reads it to show progress during an import.

## Data Type

The connector reads and writes **BSON** and **JSON**. Dsync picks the type the other side supports.

## Writing to S3

JSON documents, such as those from Cosmos DB NoSQL, are written as they are.

BSON documents, such as those from MongoDB, are converted to plain JSON (not Extended JSON):

| BSON value               | Written as                                                          |
| ------------------------ | ------------------------------------------------------------------- |
| ObjectID                 | 24-character hex string                                             |
| Date                     | RFC 3339 string in UTC, for example `"2026-11-01T10:00:00.123Z"`    |
| Int32, Int64, Double     | JSON number. A whole double has no `.0`, so `7.0` is written as `7` |
| Decimal128               | String, for example `"1.10"`                                        |
| Binary                   | Object with `Subtype` and base64 `Data` fields                      |
| Embedded document, array | JSON object, JSON array                                             |
| Null                     | `null`                                                              |

Keys are written in alphabetical order.

## Reading from S3

The connector lists every `.json` object under the prefix, except `.metadata.json`, and reads each file as one task. Files are read in parallel.

* The folder path below the prefix becomes the namespace: `<prefix>/shop/orders/x.json` is read as `shop.orders`. Files directly under the prefix go to the namespace `default`.
* Without `--namespace`, every namespace found is imported. With it, only the listed namespaces are. Rename on the way in with a mapping, for example `--namespace "table1:mydb.table1"`.
* Any file holding a JSON array of objects can be imported, not only files written by Dsync. If `.metadata.json` is missing, Dsync logs a warning and the import still runs, with progress shown as 0.

## Examples

Export two DynamoDB tables:

```bash
dsync --mode InitialSync --namespace "table1,table2" \
  dynamodb s3://my-bucket/exports --region us-east-1
```

Export MongoDB collections into compact files:

```bash
dsync --mode InitialSync --namespace "shop.orders,shop.customers" \
  mongodb://localhost:27017 s3://my-bucket/mongo --region us-east-1 --pretty-json=false
```

Import an export back into DynamoDB:

```bash
dsync --mode InitialSync s3://my-bucket/exports --region us-east-1 dynamodb
```

Check that the files parse before writing anywhere, by reading them into `/dev/null`:

```bash
dsync --mode InitialSync s3://my-bucket/exports --region us-east-1 /dev/null --log-json
```

Write to a local MinIO:

```bash
dsync --mode InitialSync --namespace "shop.orders" mongodb://localhost:27017 \
  s3://my-bucket --region us-east-1 --endpoint http://localhost:9000 --use-path-style \
  --access-key-id minioadmin --secret-access-key minioadmin
```

To watch progress in the terminal, add `--progress --logfile dsync.log`.

## Limitations

The connector writes JSON only, and BSON documents are written as plain JSON, so a MongoDB export does not round-trip exactly.

* For CSV, use the [File (CSV)](https://docs.adiom.io/reference/connectors/file.md) connector.
* It copies data once. There's no CDC, so it can't keep a bucket in sync with a database.
* BSON types aren't kept. ObjectIDs, dates and Decimal128 values are written as strings, and a whole double is written like an integer. See [Writing to S3](#writing-to-s3).
* When the files are loaded into a BSON destination such as MongoDB, every number comes back as a double, and integers beyond 2^53 lose precision. ObjectIDs and dates stay strings, including `_id`, so reloaded documents don't match the originals, and loading into the source database adds new documents next to the old ones instead of replacing them. Field order isn't kept.
* Writing to a prefix that already holds an export adds new files next to the old ones, and a later import reads both. Use a new prefix for each export, or empty the old one first.
* A file that fails to upload is logged as `Upload failed` and isn't retried, and the run carries on. Search the log for `Upload failed` after an export, and compare the counts in `.metadata.json` with the source. Dsync v0.31.0 exits with status 0 even when a step fails, so don't rely on the exit code.
* Each file is read whole into memory as one task, so keep files produced by other tools to a moderate size.
* A single write batch larger than `--max-total-memory` fails the export.
