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

# S3

## S3

An `s3` sink writes each matched event as a separate UTF-8 JSON object to Amazon S3 or an S3-compatible store (such as Cloudflare R2, MinIO, Wasabi, Backblaze B2, or DigitalOcean Spaces).

### Before you start

1. Create the bucket before you create the sink. EventStream never calls `CreateBucket`.
   * `bucket` must be `3`–`63` characters matching `^[a-z0-9][a-z0-9.-]{1,61}[a-z0-9]$`, without `..` and not formatted as an IP address.
   * If the bucket name contains a dot (`.`), set `config.path_style: true`. With `path_style: false`, requests go to `<bucket>.<host>`, and bucket names with dots are rejected.
   * Set `config.path_style: true` when `endpoint` uses an IP address.
2. Use a root HTTPS `endpoint` on port `443` or `8443` with a certificate from a public CA; `s3` sinks do not accept a custom CA bundle. The endpoint has no path other than an optional `"/"`, no query string and no `#` fragment, for example `https://s3.eu-central-1.amazonaws.com` or `https://<account_id>.r2.cloudflarestorage.com`. Set `region` to the bucket's region (`"auto"` on Cloudflare R2).
3. Grant the access key `s3:PutObject` on `arn:aws:s3:::<bucket>/*` (or `arn:aws:s3:::<bucket>/<prefix>/*` when `prefix` is non-empty). `s3:GetObject` and `s3:ListBucket` are not required. If the bucket enforces SSE-KMS default encryption, also grant `kms:GenerateDataKey` on the KMS key:

```json
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Action": ["s3:PutObject"],
      "Resource": "arn:aws:s3:::my-eventstream-archive/events/prod/*"
    }
  ]
}
```

Buckets with an Object Lock default retention period are not supported: uploads to them require a `Content-MD5` or checksum header, which EventStream does not send.

#### **Create an S3 sink**

<mark style="color:green;">`POST`</mark> `https://api-eventstream.crypto-chief.com/v1/sinks/create`

**Headers**

| Name            | Value                                                                                                                        |
| --------------- | ---------------------------------------------------------------------------------------------------------------------------- |
| Content-Type    | `application/json`                                                                                                           |
| Merchant        | Your Merchant ID                                                                                                             |
| X-CC-Timestamp  | Unix time in seconds                                                                                                         |
| X-CC-Nonce      | A new random value for every request                                                                                         |
| X-CC-Signature  | [Request signature](https://crypto-chief.gitbook.io/chief-event-stream/getting-started/authentication.md)                    |
| Idempotency-Key | **Required.** [Format](https://crypto-chief.gitbook.io/chief-event-stream/getting-started/authentication.md#idempotency-key) |

**Body**

Unknown fields return `400` `UNKNOWN_FIELD`.

| Name                            | Type    | Required | Description                                                                                                                                                                                                     |
| ------------------------------- | ------- | -------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `kind`                          | string  | true     | `"s3"`.                                                                                                                                                                                                         |
| `config`                        | object  | true     | Sink configuration.                                                                                                                                                                                             |
| `config.endpoint`               | string  | true     | Root HTTPS S3 endpoint URL (`^https://`, up to `2,048` characters, port `443` or `8443`, path empty or `"/"`, no query or `#` fragment).                                                                        |
| `config.region`                 | string  | true     | SigV4 signing region (`^[A-Za-z0-9_-]{1,64}$`, such as `"eu-central-1"` or `"auto"`).                                                                                                                           |
| `config.bucket`                 | string  | true     | Bucket name (`^[a-z0-9][a-z0-9.-]{1,61}[a-z0-9]$`, no `..`, not an IP literal; dots require `path_style: true`).                                                                                                |
| `config.prefix`                 | string  | true     | Key prefix (`0`–`256` characters after trimming leading and trailing `/`). Pass `""` for no prefix. Must not contain `..`, `\`, `?`, `#`, `@`, `\r`, `\n`, or `\t`.                                             |
| `config.path_style`             | boolean | true     | `true` uses `https://<host>[:port]/<bucket>/<key>`; `false` uses `https://<bucket>.<host>[:port]/<key>`.                                                                                                        |
| `config.label`                  | string  | false    | Display label, up to `100` characters.                                                                                                                                                                          |
| `config.rate_per_second`        | integer | false    | Maximum deliveries per second for this sink, `1`–`20`. Default `20`.                                                                                                                                            |
| `config.enabled`                | boolean | false    | Default `true`. With `false`, unsent deliveries stay `"queued"` and `status` stays `"active"`; see [`config.enabled`](https://crypto-chief.gitbook.io/chief-event-stream/api-reference/sinks.md#create-a-sink). |
| `credentials`                   | object  | true     | Write-only. In `sinks/get`, `credentials_meta.access_key_id.last4` exposes the last `4` characters; `secret_access_key.last4` and `session_token.last4` are `null`.                                             |
| `credentials.access_key_id`     | string  | true     | S3 access key ID (non-empty, no whitespace).                                                                                                                                                                    |
| `credentials.secret_access_key` | string  | true     | S3 secret access key (non-empty, no `\r` or `\n`).                                                                                                                                                              |
| `credentials.session_token`     | string  | false    | Optional STS session token. When non-empty, sent as `X-Amz-Security-Token` and included in the SigV4 signature.                                                                                                 |

```json
{
  "kind": "s3",
  "config": {
    "endpoint": "https://s3.eu-central-1.amazonaws.com",
    "region": "eu-central-1",
    "bucket": "my-eventstream-archive",
    "prefix": "events/prod",
    "path_style": false,
    "label": "Production S3 archive",
    "rate_per_second": 20
  },
  "credentials": {
    "access_key_id": "AKIAIOSFODNN7EXAMPLE",
    "secret_access_key": "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY"
  }
}
```

**Response**

{% tabs %}
{% tab title="201" %}

```json
{
  "ok": true,
  "data": {
    "sink_id": "019a0000-0000-7000-8000-000000000001",
    "kind": "s3",
    "status": "active",
    "secret": null,
    "secret_version": 0,
    "config": {
      "endpoint": "https://s3.eu-central-1.amazonaws.com",
      "region": "eu-central-1",
      "bucket": "my-eventstream-archive",
      "prefix": "events/prod",
      "path_style": false,
      "label": "Production S3 archive",
      "rate_per_second": 20
    }
  },
  "request_id": "019a0000-0000-7000-8000-000000000099"
}
```

{% endtab %}

{% tab title="422" %}

```json
{
  "ok": false,
  "error": "DESTINATION_FORBIDDEN",
  "msg": "destination is forbidden by egress policy",
  "request_id": "019a0000-0000-7000-8000-000000000099",
  "details": {
    "field": "config.endpoint"
  }
}
```

{% endtab %}

{% tab title="429" %}

```json
{
  "ok": false,
  "error": "PROJECT_LIMIT_EXCEEDED",
  "msg": "sink limit reached",
  "request_id": "019a0000-0000-7000-8000-000000000099",
  "details": {}
}
```

{% endtab %}
{% endtabs %}

### What arrives

Each matched event is uploaded with an HTTP `PUT` signed with `AWS4-HMAC-SHA256` (`service: "s3"`). The request headers are `Content-Type: application/json; charset=utf-8`, `User-Agent: CryptoChief-EventStream/1`, `X-Amz-Date`, `X-Amz-Content-Sha256` (lowercase hex SHA-256 of the body), `Authorization`, `X-Amz-Security-Token` (when `session_token` is configured), and `X-CC-Replay-Run` (the `job_id` of [`deliveries/resend` or `deliveries/resend-bulk`](https://crypto-chief.gitbook.io/chief-event-stream/api-reference/deliveries.md) when a `succeeded` delivery is resent).

* **Object key:**
  * Non-empty `prefix`: `<prefix>/<project_id>/<subscription_id>/<event_id>.json`
  * Empty `prefix` (`""`): `<project_id>/<subscription_id>/<event_id>.json`
* **Object body:** the exact UTF-8 JSON [`Envelope`](https://crypto-chief.gitbook.io/chief-event-stream/webhooks/event-envelope.md) of the single event (`1` event per object, uncompressed).

Example object written to `s3://my-eventstream-archive/events/prod/3f2a1b4c-5d6e-7f80-9a1b-2c3d4e5f6071/019a0000-0000-7000-8000-000000000003/019a0000-0000-7000-8000-000000000011.json`:

```json
{
  "schema_version": 1,
  "event_id": "019a0000-0000-7000-8000-000000000011",
  "occurrence_id": "2fc9669e6460937a2d41594eeac53b4718dc74b5c7d82a0e60432f308bbaabde",
  "project_id": "3f2a1b4c-5d6e-7f80-9a1b-2c3d4e5f6071",
  "subscription_id": "019a0000-0000-7000-8000-000000000003",
  "revision": 1,
  "sequence": "42",
  "type": "transfer.token",
  "network": "ETH_MAINNET",
  "stage": "confirmed",
  "occurred_at": "2026-10-27T00:00:00.000Z",
  "observed_at": "2026-10-27T00:00:24.100Z",
  "block": {
    "height": "24000000",
    "hash": "0xbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb",
    "parent_hash": "0xcccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc",
    "timestamp": "2026-10-27T00:00:00.000Z"
  },
  "transaction": {
    "hash": "0xdddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd",
    "index": 0,
    "success": true,
    "fee": {
      "asset": "native",
      "raw": "21000000000000"
    }
  },
  "confirmations": "2",
  "finality": {
    "basis": "finalized_tag",
    "economic": true
  },
  "relation": {
    "transaction_key": "0xdddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd",
    "replaces_event_ids": [],
    "reappears_after": null,
    "replaces_transaction": null
  },
  "origin": {
    "kind": "live",
    "run_id": null
  },
  "payload": {
    "direction": "in",
    "from": "0x0000000000000000000000000000000000000002",
    "to": "0x0000000000000000000000000000000000000001",
    "asset": {
      "kind": "token",
      "standard": "erc20",
      "id": "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48",
      "contract": "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48",
      "symbol": "USDC",
      "decimals": 6,
      "token_id": null
    },
    "amount": {
      "raw": "125500000",
      "decimals": 6,
      "scale": null
    },
    "source": {
      "kind": "log",
      "path": "log/7/erc20",
      "success": true,
      "memo": null,
      "source_tag": null,
      "destination_tag": null
    },
    "utxo": null
  },
  "enrichments": {},
  "transformed_payload": null
}
```

### Retries and errors

A delivery is acknowledged on HTTP `200`–`299`.

* **Retried:** network errors and timeouts, and HTTP `408`, `425`, `429`, `500`–`599` (including S3 `503 SlowDown` and `500 InternalError`), with the schedule and `Retry-After` rules in [Retries and Ordering](https://crypto-chief.gitbook.io/chief-event-stream/webhooks/retries-and-ordering.md).
* **Permanent failures (no retries; delivery moves to `dead`):**
  * Non-public IP in DNS resolution (checked on `<bucket>.<host>` when `path_style` is `false`, or `<host>` when `true`) or TLS certificate error: pauses the **entire sink** with `pause_reason: "security_blocked"`.
  * HTTP `401` or `403` (`InvalidAccessKeyId`, `SignatureDoesNotMatch`, `AccessDenied`): pauses the **entire sink** with `pause_reason: "destination_auth"`.
  * HTTP `404` or `410` (`NoSuchBucket`): pauses the **entire sink** with `pause_reason: "destination_gone"`.
  * HTTP `400` or `422` (such as `ExpiredToken`, `InvalidToken`, or `AuthorizationHeaderMalformed` for a wrong `region`): pauses **only that `(subscription_id, sink_id)` lane** (`"destination_rejected"`), unless aggregate failures trigger whole-sink `"failures"`.
  * HTTP `300`–`399` (such as S3 `301`/`307` wrong-region redirects, which are never followed), or a `bucket`, `region`, `prefix`, `endpoint` path or query, or `credentials` value that breaks the rules above: pauses the **entire sink** with `pause_reason: "destination_rejected"`. `sinks/create` checks only the schema and the `endpoint` host and port; the other rules are checked when a delivery or [`sinks/test`](https://crypto-chief.gitbook.io/chief-event-stream/api-reference/sinks.md#send-a-test-delivery) runs.
* **How to resume:** fix the bucket permissions, or the `config` / `credentials` value that caused the pause, then resume the sink as described in [Ordering, retries, and auto-pause](https://crypto-chief.gitbook.io/chief-event-stream/sinks/overview.md#ordering-retries-and-auto-pause).

### Duplicates

The object key `[<prefix>/]<project_id>/<subscription_id>/<event_id>.json` is fixed per event, and each stage has its own `event_id`. Retries and [`deliveries/resend`](https://crypto-chief.gitbook.io/chief-event-stream/api-reference/deliveries.md#resend-a-delivery) overwrite the same object with an idempotent `PUT`. In a versioned bucket, each overwrite adds an object version. A service that consumes bucket `ObjectCreated:Put` notifications should deduplicate by object key or `event_id`.

### Test delivery

Calling [`sinks/test`](https://crypto-chief.gitbook.io/chief-event-stream/api-reference/sinks.md#send-a-test-delivery) with `{"sink_id": "<uuidv7>", "sample_type": "system.test"}` uploads a [`system.test`](https://crypto-chief.gitbook.io/pages/X84VQ5lQlasjJZqaqw9H#system.test) JSON object to `[<prefix>/]<project_id>/system/<delivery_id>.json`, with the segment `"system"` in place of `<subscription_id>`:

```json
{
  "schema_version": 1,
  "event_id": "019a0000-0000-7000-8000-000000000002",
  "project_id": "3f2a1b4c-5d6e-7f80-9a1b-2c3d4e5f6071",
  "type": "system.test",
  "is_test": true,
  "created_at": "2026-10-27T00:00:00.000Z",
  "payload": {
    "message": "EventStream test",
    "sink_id": "019a0000-0000-7000-8000-000000000001",
    "generated_at": "2026-10-27T00:00:00.000Z"
  }
}
```

### What it costs

S3 deliveries have no channel fee. Events are billed as described in [Billing](https://crypto-chief.gitbook.io/chief-event-stream/getting-started/billing.md).

### Network access

EventStream connects to your S3 `endpoint` (and `<bucket>.<host>` when `path_style` is `false`) over HTTPS on TCP port `443` or `8443`. If a firewall or a bucket policy (`aws:SourceIp`) restricts source addresses, allow the EventStream addresses listed in [Network access](https://crypto-chief.gitbook.io/chief-event-stream/sinks/overview.md#network-access).

### Example

`request()` is defined in [Authentication](https://crypto-chief.gitbook.io/chief-event-stream/getting-started/authentication.md). Both `sinks/create` and `sinks/test` require an `Idempotency-Key`.

{% tabs %}
{% tab title="JavaScript" %}

```javascript
import crypto from "node:crypto";

const sink = await request(
  "sinks/create",
  {
    kind: "s3",
    config: {
      endpoint: "https://s3.eu-central-1.amazonaws.com",
      region: "eu-central-1",
      bucket: "my-eventstream-archive",
      prefix: "events/prod",
      path_style: false,
      label: "Production S3 archive",
      rate_per_second: 20,
    },
    credentials: {
      access_key_id: "AKIAIOSFODNN7EXAMPLE",
      secret_access_key: "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY",
    },
  },
  crypto.randomUUID()
);

const test = await request(
  "sinks/test",
  {
    sink_id: sink.sink_id,
    sample_type: "system.test",
  },
  crypto.randomUUID()
);

console.log(sink.sink_id, test.delivery_id);
```

{% endtab %}

{% tab title="PHP" %}

```php
$sink = request(
    'sinks/create',
    [
        'kind' => 's3',
        'config' => [
            'endpoint'        => 'https://s3.eu-central-1.amazonaws.com',
            'region'          => 'eu-central-1',
            'bucket'          => 'my-eventstream-archive',
            'prefix'          => 'events/prod',
            'path_style'      => false,
            'label'           => 'Production S3 archive',
            'rate_per_second' => 20,
        ],
        'credentials' => [
            'access_key_id'     => 'AKIAIOSFODNN7EXAMPLE',
            'secret_access_key' => 'wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY',
        ],
    ],
    bin2hex(random_bytes(16))
);

$test = request(
    'sinks/test',
    [
        'sink_id'     => $sink['sink_id'],
        'sample_type' => 'system.test',
    ],
    bin2hex(random_bytes(16))
);

echo $sink['sink_id'] . ' ' . $test['delivery_id'] . "\n";
```

{% endtab %}

{% tab title="GO" %}

```go
sink, err := request("sinks/create", map[string]any{
	"kind": "s3",
	"config": map[string]any{
		"endpoint":        "https://s3.eu-central-1.amazonaws.com",
		"region":          "eu-central-1",
		"bucket":          "my-eventstream-archive",
		"prefix":          "events/prod",
		"path_style":      false,
		"label":           "Production S3 archive",
		"rate_per_second": 20,
	},
	"credentials": map[string]any{
		"access_key_id":     "AKIAIOSFODNN7EXAMPLE",
		"secret_access_key": "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY",
	},
}, rand.Text())
if err != nil {
	panic(err)
}

test, err := request("sinks/test", map[string]any{
	"sink_id":     sink["sink_id"],
	"sample_type": "system.test",
}, rand.Text())
if err != nil {
	panic(err)
}

fmt.Println(sink["sink_id"], test["delivery_id"])
```

{% endtab %}

{% tab title="Python" %}

```python
import secrets

sink = request(
    "sinks/create",
    {
        "kind": "s3",
        "config": {
            "endpoint": "https://s3.eu-central-1.amazonaws.com",
            "region": "eu-central-1",
            "bucket": "my-eventstream-archive",
            "prefix": "events/prod",
            "path_style": False,
            "label": "Production S3 archive",
            "rate_per_second": 20,
        },
        "credentials": {
            "access_key_id": "AKIAIOSFODNN7EXAMPLE",
            "secret_access_key": "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY",
        },
    },
    secrets.token_hex(16),
)

test = request(
    "sinks/test",
    {
        "sink_id": sink["sink_id"],
        "sample_type": "system.test",
    },
    secrets.token_hex(16),
)

print(sink["sink_id"], test["delivery_id"])
```

{% endtab %}

{% tab title="curl" %}

```bash
sink=$(request sinks/create \
  '{"kind":"s3","config":{"endpoint":"https://s3.eu-central-1.amazonaws.com","region":"eu-central-1","bucket":"my-eventstream-archive","prefix":"events/prod","path_style":false,"label":"Production S3 archive","rate_per_second":20},"credentials":{"access_key_id":"AKIAIOSFODNN7EXAMPLE","secret_access_key":"wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY"}}' \
  "$(openssl rand -hex 16)")

sink_id=$(jq -r '.sink_id' <<< "$sink")

request sinks/test \
  "{\"sink_id\":\"$sink_id\",\"sample_type\":\"system.test\"}" \
  "$(openssl rand -hex 16)"
```

{% endtab %}
{% endtabs %}
