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

# Concepts: How S3 ingestion works

> This document explains S3 ingestion, the bucket connection and the ingestion-error bucket that set it up, the folders of usage-event collections, and the files that Zenskar reads.

## S3 ingestion

> [accordion] Map of concepts
>
> | Concept | What it is | What it is used for |
> | - | - | - |
> | [S3 ingestion](#s3-ingestion-usage-events-from-files-in-amazon-s3) | The import of usage events from files in an Amazon S3 bucket of your organization | S3 ingestion is set for each usage-event collection on its own. |
> | [Bucket connection](#bucket-connections-one-bucket-for-the-organization) | The setting that tells Zenskar which S3 bucket of your organization stores the files of usage events | An organization has one bucket connection. |
> | [Processor role](#bucket-connections-one-bucket-for-the-organization) | The AWS IAM role that Zenskar uses to read the files in the S3 bucket that a bucket connection names | Zenskar reads the files in the S3 bucket of a bucket connection through the processor role. |
> | [Zenskar SQS queue](#bucket-connections-one-bucket-for-the-organization) | The Amazon SQS queue of Zenskar that receives a notification when a new file arrives in the S3 bucket that a bucket connection names | Zenskar learns about each new file in the S3 bucket of a bucket connection through the Zenskar SQS queue. |
> | [Ingestion-error bucket](#ingestion-error-buckets-where-rejected-files-go) | An S3 bucket of your organization in which Zenskar writes an error file for each file that S3 ingestion rejects | An organization can set one ingestion-error bucket with its bucket connection. |
> | [Error file](#ingestion-error-buckets-where-rejected-files-go) | A CSV file that Zenskar writes to an ingestion-error bucket about a file that S3 ingestion rejects | Each file that S3 ingestion rejects gets one error file in the ingestion-error bucket. |
> | [Error folder](#folders-of-usage-event-collections) | A folder of the ingestion-error bucket in which Zenskar writes the error files of one usage-event collection | A usage-event collection can have one error folder in the ingestion-error bucket. |

> [accordion] Related modules
>
> The following modules use Usage:
>
> | Module | Details |
> | - | - |
> | [Webhook alerts](https://zenskar.com/docs/20260301/zenskar-modules/settings/webhook-alerts.md#usage-event-ingestion) | A webhook alert can report the result of each file that S3 ingestion reads. |

## S3 ingestion: usage events from files in Amazon S3

**S3 ingestion** is the import of [usage events](https://zenskar.com/docs/20260301/zenskar-modules/usage/glossary.md#usage-event) from files in an [Amazon S3 bucket](https://docs.aws.amazon.com/AmazonS3/latest/userguide/UsingBucket.html) of your [organization](https://zenskar.com/docs/20260301/zenskar-modules/settings/glossary.md#organization).

> [!NOTE]
>
> S3 ingestion is set for each [usage-event collection](https://zenskar.com/docs/20260301/zenskar-modules/usage/glossary.md#usage-event-collection) on its own. It adds one more way to send usage events to that usage-event collection, alongside the other ways, such as its [API endpoint](https://developer.mozilla.org/en-US/docs/Glossary/REST) and CSV files. See [Concepts: How usage events work](https://zenskar.com/docs/20260301/zenskar-modules/usage/concepts/usage-events.md).

With S3 ingestion, your systems put [usage data](https://zenskar.com/docs/20260301/zenskar-modules/usage/glossary.md#usage) in files in your own bucket, and Zenskar fetches each new file as it arrives. S3 ingestion suits systems that already export usage data to files on a schedule. See [Ways to send usage events](https://zenskar.com/docs/20260301/zenskar-modules/usage/concepts/usage-events.md#ways-to-send-usage-events).

Two settings tell Zenskar which files to read and where their usage events go:

* The [bucket connection](#bucket-connections-one-bucket-for-the-organization) names the one bucket that Zenskar reads for your organization.
* Each usage-event collection that uses S3 ingestion has its own [folder](https://docs.aws.amazon.com/AmazonS3/latest/userguide/using-folders.html) in that bucket. Zenskar stores the rows of each file in the folder as usage events of that usage-event collection.

Zenskar reads only the files that arrive after S3 ingestion is set up.

For example, a nightly job writes the API calls of October 1 to `api_calls/2026-10-01.csv`. The folder `api_calls` belongs to the usage-event collection `api_calls`, so each row of the file becomes one usage event of `api_calls`.

```mermaid theme={null}
flowchart LR
  A["Request to the API endpoint"] -->|"Usage events"| U["Usage-event collection api_calls"]
  C["CSV file"] -->|"Usage events"| U
  subgraph B["Your S3 bucket"]
    F["Folder api_calls<br/>File 2026-10-01.csv"]
  end
  F -->|"S3 ingestion: one usage event for each row"| U
```

This conceptual diagram shows S3 ingestion as one of the ways that usage events reach a usage-event collection.

## Bucket connections: one bucket for the organization

A **bucket connection** is the setting that tells Zenskar which S3 bucket of your organization stores the files of usage events.

> [!NOTE]
>
> Your organization can have one bucket connection. Its bucket must be in the AWS region `us-east-1`.

The bucket stays in your AWS account. Zenskar reads the files in it, and never changes or deletes them.

Zenskar reads the bucket through two AWS resources of its own:

* The **processor role** is the [AWS IAM role](https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles.html) that Zenskar uses to read the files in the S3 bucket that a bucket connection names.
* The **Zenskar SQS queue** is the [Amazon SQS queue](https://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/welcome.html) of Zenskar that receives a notification when a new file arrives in the S3 bucket that a bucket connection names.

Two AWS settings on your bucket give these resources access, each through the [ARN](https://docs.aws.amazon.com/IAM/latest/UserGuide/reference-arns.html) of its resource:

| AWS setting | What it does |
| - | - |
| [Bucket policy](https://docs.aws.amazon.com/AmazonS3/latest/userguide/bucket-policies.html) | It grants the processor role read access to the files in the bucket. |
| [Event notification](https://docs.aws.amazon.com/AmazonS3/latest/userguide/EventNotifications.html) | It sends a notification to the Zenskar SQS queue for each new file in the bucket. |

```mermaid theme={null}
sequenceDiagram
  autonumber
  participant B as Your S3 bucket
  participant Q as Zenskar SQS queue
  participant P as Processor role
  B->>Q: Sends an event notification for a new file
  Q->>P: Reports the new file
  P->>B: Reads the file, as the bucket policy allows
```

This conceptual diagram shows how Zenskar learns about a new file and reads it.

> [!WARNING]
>
> The event notification must go directly from the bucket to the Zenskar SQS queue. Zenskar ignores a notification that passes through Amazon SNS or Amazon EventBridge, so it never reads the file.

Zenskar does not check a bucket connection when it is saved, and the bucket connection counts as connected right away. A mistake in either AWS setting shows only when files arrive:

| Mistake | Effect |
| - | - |
| The bucket policy is wrong. | Zenskar cannot read the files, so it rejects them. |
| The event notification is wrong. | Zenskar never learns that the files arrived. |

Each usage-event collection keeps the bucket that was connected when its S3 ingestion was last set up. When the bucket connection changes to another bucket, Zenskar reads the new bucket for a usage-event collection only after its S3 ingestion is set up again.

> [!CAUTION]
>
> Disconnecting the bucket connection turns off S3 ingestion on every usage-event collection, and clears the folder and the [error folder](#folders-of-usage-event-collections) of each one. Connecting a bucket again does not restore them. Note the folders of your usage-event collections before you disconnect.

See [Prepare the bucket in AWS](https://zenskar.com/docs/20260301/zenskar-modules/usage/how-to-guides/s3-ingestion.md#prepare-the-bucket-in-aws).

See [Connect the bucket in Zenskar](https://zenskar.com/docs/20260301/zenskar-modules/usage/how-to-guides/s3-ingestion.md#connect-the-bucket-in-zenskar).

## Ingestion-error buckets: where rejected files go

An **ingestion-error bucket** is an S3 bucket of your organization in which Zenskar writes an [error file](#ingestion-error-buckets-where-rejected-files-go) for each file that S3 ingestion rejects.

Zenskar rejects a file as a whole. One row that fails is enough, and the file then adds no usage events. See [Files that S3 ingestion reads](#files-that-s3-ingestion-reads).

An ingestion-error bucket is optional. Without one, Zenskar writes no error file. Your organization sets the ingestion-error bucket together with its bucket connection. It can be the same bucket or another bucket, and it must be in the AWS region `us-east-1`. Its bucket policy grants the processor role write access, so that Zenskar can write error files to it.

An **error file** is a CSV file that Zenskar writes to an ingestion-error bucket about a file that S3 ingestion rejects.

Zenskar writes one of two error files. In the name of an error file, `<name>` is the name of the rejected file without `.csv`, and `<ID>` identifies the processing of the file.

| Error file | When Zenskar writes it | What it holds |
| - | - | - |
| `<name>_<ID>_errors.csv` | Some rows of the file fail validation. | One row for each rejected row, with its line number, column, error type, error message, and content |
| `<name>_<ID>_error_summary.csv` | The file fails as a whole. For example, its columns do not match the [data schema](https://zenskar.com/docs/20260301/zenskar-modules/usage/glossary.md#data-schema), it is empty or too large, or Zenskar cannot read it. | The name of the file and the error |

Zenskar writes the error files of a usage-event collection to its [error folder](#folders-of-usage-event-collections). Without an error folder, Zenskar writes them to the folder `errors`.

For example, one row of `api_calls/2026-10-01.csv` has text in a number field, so Zenskar rejects the file. With no error folder, the error file is `errors/2026-10-01_<ID>_errors.csv`.

A file that Zenskar does not read gets no error file, such as a file whose name does not end in `.csv`, or a file in a folder that belongs to no usage-event collection.

See [Prepare an ingestion-error bucket](https://zenskar.com/docs/20260301/zenskar-modules/usage/how-to-guides/s3-ingestion.md#prepare-an-ingestion-error-bucket).

## Folders of usage-event collections

S3 ingestion is on or off for each usage-event collection. A usage-event collection with S3 ingestion on has its own folder in your S3 bucket. Zenskar reads each new file in that folder. By default, the folder has the name of the [API slug](https://zenskar.com/docs/20260301/zenskar-modules/usage/glossary.md#api-slug) of the usage-event collection. Two usage-event collections cannot have the same folder.

A folder is a path in the bucket, such as `api_calls` or `usage/api_calls`. The path has no trailing slash, and no part of it is `.` or `..`.

Zenskar reads a file only when its folder matches the folder of a usage-event collection exactly. The folder of a file is the whole path before its name:

| File | Folder of the file | Read for the usage-event collection with the folder `usage/api_calls` |
| - | - | - |
| `usage/api_calls/2026-10-01.csv` | `usage/api_calls` | Yes |
| `usage/api_calls/old/2026-09-30.csv` | `usage/api_calls/old` | No |
| `2026-10-01.csv` | None, because the file is at the top level of the bucket | No |

An **error folder** is a folder of the ingestion-error bucket in which Zenskar writes the error files of one usage-event collection.

The error folder is optional. A usage-event collection can have one only when your organization has an ingestion-error bucket. When the ingestion-error bucket is your S3 bucket itself, the error folder cannot be the folder of any usage-event collection.

> [!CAUTION]
>
> Turning off S3 ingestion for a usage-event collection stops Zenskar from reading its folder right away, and clears its folder and its error folder. Turning S3 ingestion on again does not restore them. Note both folders before you turn S3 ingestion off.

See [Set up S3 ingestion for a usage-event collection](https://zenskar.com/docs/20260301/zenskar-modules/usage/how-to-guides/usage-events.md#set-up-s3-ingestion-for-a-usage-event-collection).

## Files that S3 ingestion reads

S3 ingestion reads CSV files. Zenskar reads a file only when its name ends in `.csv`, in uppercase or lowercase letters, such as `.CSV`. Zenskar ignores every other file.

The first row of a file is a header row that names the fields of the [data schema](https://zenskar.com/docs/20260301/zenskar-modules/usage/glossary.md#data-schema) of the usage-event collection:

* The header names every field, including the [root fields](https://zenskar.com/docs/20260301/zenskar-modules/usage/glossary.md#root-field) `customer_id` and `timestamp`.
* The header names no column that the data schema does not have.
* The columns can be in any order.
* The `data.` prefix of a [data field](https://zenskar.com/docs/20260301/zenskar-modules/usage/glossary.md#data-field) is optional. For example, the header `region` names the data field `data.region`.

Each value fits the data type of its field. See [Data fields: the details that you add](https://zenskar.com/docs/20260301/zenskar-modules/usage/concepts/usage-events.md#data-fields-the-details-that-you-add).

A file can be at most 200 MB. A file without rows is rejected.

Zenskar checks every row of a file before it stores any row, so a file is stored whole or not at all. See [Ingestion-error buckets: where rejected files go](#ingestion-error-buckets-where-rejected-files-go).

```mermaid theme={null}
sequenceDiagram
  autonumber
  participant Q as Zenskar SQS queue
  participant P as Processor role
  participant C as Usage-event collection
  participant E as Ingestion-error bucket
  Note over Q: api_calls/2026-10-01.csv arrives
  Q->>P: Reports the new file
  P->>P: Checks every row against the data schema
  alt Every row passes
    P->>C: Stores the rows as usage events
  else A row fails
    P->>E: Writes an error file
  end
```

This conceptual diagram shows how S3 ingestion processes one file.

Zenskar can skip a file whose content matches a file that it stored recently, but it does not guarantee to skip it. Sending the same file twice can store its usage events twice.

Zenskar downloads a file when it processes it. If the processing fails for a temporary reason, Zenskar downloads the file again and retries. After the usage events of a file appear in the usage-event collection, you can delete the file from your bucket.

See [Check that S3 ingestion works](https://zenskar.com/docs/20260301/zenskar-modules/usage/how-to-guides/s3-ingestion.md#check-that-s3-ingestion-works).


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