---
title: Drain Data to Amazon S3
description: Learn how to configure AWS IAM and Amazon S3 so Drains can write logs, traces, Web Analytics, Speed Insights, AI Gateway traces, Connect events, and...
url: "https://vercel.com/docs/drains/s3"
last_updated: 2026-11-13
related:
  - /docs/plans/enterprise
  - /docs/accounts
  - /docs/drains/using-drains
  - /docs/cli/drains
  - /docs/drains/reference/logs
install_vercel_plugin: npx plugins add vercel/vercel-plugin
search_with_vercel_cli: npx vercel@latest docs search "<query>"
search_kb_with_vercel_cli: npx vercel@latest kb search "<query>"
---

# Drain Data to Amazon S3

> Drains to Amazon S3 are available on Enterprise and Pro plans

Drains can write logs, traces, Web Analytics, Speed Insights, AI Gateway traces, Connect events, and Audit Logs directly to your Amazon S3 bucket. Use this setup when you want drain data stored in your AWS account for archives, compliance retention, or downstream analysis. Audit Log Drains to S3 require an [Enterprise](/docs/plans/enterprise) plan, the same as every Audit Log Drain.

Vercel writes to S3 by assuming an AWS Identity and Access Management (IAM) role in your AWS account with [AWS Security Token Service (AWS STS)](https://docs.aws.amazon.com/STS/latest/APIReference/welcome.html). You keep ownership of the bucket and grant Vercel write access only to the bucket path you configure.

Follow the steps below to create the IAM role, attach write permissions, configure the drain, and run a test delivery. After setup, use [Configuration reference](#configuration-reference) for field values, [File structure](#file-structure) for S3 object paths and contents, and [Advanced options](#advanced-options) for encryption and object ACL settings.

## Set up a drain to Amazon S3

Before you configure the drain, make sure you have:

- Access to create or update an S3 bucket, IAM role, and IAM policy
- Access to view the S3 bucket default encryption and Object Ownership settings
- Access to update the AWS Key Management Service (AWS KMS) key policy if your bucket uses a customer managed AWS KMS key
- The full KMS key ARN, if the bucket uses SSE-KMS or DSSE-KMS with a customer managed key
- An S3 bucket and optional prefix for drain objects
- The AWS region where the bucket is located
- Your [Vercel team ID](/docs/accounts#find-your-team-id)
- The Vercel S3 drain writer role ARN: `arn:aws:iam::977805900156:role/vercel-drains-s3-writer`

The S3 bucket and IAM role must be in the same AWS account. The KMS key can be in another AWS account.

- ### Create an IAM role
  Create an IAM role in the same AWS account as the bucket. In AWS IAM, select **Custom trust policy** as the trusted entity type.

  Use this IAM role ARN as the `roleArn` value in Vercel. Attach the permissions for your S3 encryption mode to the same IAM role.

  The IAM role trust policy must allow the Vercel S3 drain writer role to call `sts:AssumeRole` and must require the external ID for your Vercel team.

  Replace:
  - `<your-team-id>` with your Vercel team ID, for example `team_123`
  ```json
  {
    "Version": "2012-10-17",
    "Statement": [
      {
        "Effect": "Allow",
        "Principal": {
          "AWS": "arn:aws:iam::977805900156:role/vercel-drains-s3-writer"
        },
        "Action": "sts:AssumeRole",
        "Condition": {
          "StringEquals": {
            "sts:ExternalId": "vercel-team:<your-team-id>"
          }
        }
      }
    ]
  }
  ```
  The external ID ties the role to one Vercel team and helps prevent the [confused deputy problem](https://docs.aws.amazon.com/IAM/latest/UserGuide/confused-deputy.html). Use the **exact** `vercel-team:<your-team-id>` value. **Do not use wildcard values** such as `vercel-team:*`, because they can allow other Vercel teams to use the role ARN.

  The setup uses two IAM role ARNs:

  | Role                         | Owner            | Where to use it                                                                 |
  | ---------------------------- | ---------------- | ------------------------------------------------------------------------------- |
  | Vercel S3 drain writer role  | Vercel           | Principal in your IAM role trust policy                                         |
  | Your IAM role                | Your AWS account | `roleArn` in Vercel and identity-based permissions                              |

- ### Attach write permissions
  Attach an identity-based IAM permissions policy to your IAM role. Choose the policy that matches your bucket encryption setup.

  Both permission options use the following S3 resource mapping. Scope the S3 resource to the exact bucket or prefix in the `endpoint`.

  | Vercel `endpoint`            | IAM policy `Resource`                    |
  | ---------------------------- | ---------------------------------------- |
  | `s3://<bucket-name>`           | `arn:aws:s3:::<bucket-name>/*`             |
  | `s3://<bucket-name>/drain-data` | `arn:aws:s3:::<bucket-name>/drain-data/*`  |

  Test deliveries write objects under `_test/`. If the `endpoint` is `s3://<bucket-name>`, your IAM role must allow `s3:PutObject` on `arn:aws:s3:::<bucket-name>/*` so test and production objects can be written.

  If you set **Object ACL** in Vercel, add `s3:PutObjectAcl` to the same S3 statement. Amazon S3 requires `s3:PutObjectAcl` when a `PutObject` request includes an ACL header.
  #### S3 or AWS managed key
  Use this option when the bucket uses SSE-S3, or SSE-KMS with the AWS managed `aws/s3` key. For SSE-KMS with `aws/s3`, leave **KMS key ARN** empty.

  The following example allows writes to `s3://<bucket-name>/drain-data`:
  ```jsonc
  {
    "Version": "2012-10-17",
    "Statement": [
      {
        "Sid": "AllowS3Writes",
        "Effect": "Allow",
        "Action": [
          "s3:PutObject",
          // Include when Object ACL is set in the drain configuration.
          "s3:PutObjectAcl"
        ],
        "Resource": "arn:aws:s3:::<bucket-name>/drain-data/*"
      }
    ]
  }
  ```
  #### Customer managed KMS key
  Use this option when the bucket uses SSE-KMS or DSSE-KMS with an AWS KMS key that you manage. This includes buckets whose default encryption uses a customer managed AWS KMS key. Set `kmsKeyId` to that key's full ARN. Without `kmsKeyId`, S3 encrypts objects with the AWS managed `aws/s3` key, not the bucket default key.

  The identity-based IAM policy must allow `s3:PutObject` on the destination path and `kms:GenerateDataKey` on the KMS key ARN. `kms:CallerAccount` is the account in `roleArn`, not the account in the key ARN. The key can be in another AWS account.

  The following example allows writes to `s3://<bucket-name>/drain-data` with a customer managed AWS KMS key in `<aws-region>`:
  ```jsonc
  {
    "Version": "2012-10-17",
    "Statement": [
      {
        "Sid": "AllowS3Writes",
        "Effect": "Allow",
        "Action": [
          "s3:PutObject",
          // Include when Object ACL is set in the drain configuration.
          "s3:PutObjectAcl"
        ],
        "Resource": "arn:aws:s3:::<bucket-name>/drain-data/*"
      },
      {
        "Sid": "AllowKmsForS3Writes",
        "Effect": "Allow",
        "Action": "kms:GenerateDataKey",
        "Resource": "arn:aws:kms:<aws-region>:<key-account-id>:key/<kms-key-id>",
        "Condition": {
          "StringEquals": {
            "kms:CallerAccount": "<role-account-id>",
            "kms:ViaService": "s3.<aws-region>.amazonaws.com"
          }
        }
      }
    ]
  }
  ```
  Add this statement to the key policy for the key in `kmsKeyId`. Edit that policy in the AWS account that owns the key. That account can differ from the bucket account. `kms:CallerAccount` stays the account in `roleArn`. Keep your existing key administration statements:
  ```json
  {
    "Sid": "AllowVercelDrainRoleToUseKeyViaS3",
    "Effect": "Allow",
    "Principal": {
      "AWS": "<your-iam-role-arn>"
    },
    "Action": "kms:GenerateDataKey",
    "Resource": "*",
    "Condition": {
      "StringEquals": {
        "kms:CallerAccount": "<role-account-id>",
        "kms:ViaService": "s3.<aws-region>.amazonaws.com"
      }
    }
  }
  ```
  Unless you set **Object ACL**, Vercel does not need `s3:PutObjectAcl`, `s3:GetObject`, `s3:ListBucket`, `s3:DeleteObject`, or `s3:GetBucketLocation`.

- ### Configure the drain in Vercel
  In Vercel, [add a drain](/docs/drains/using-drains#configuring-drains), choose its data type and projects, and choose **Amazon S3** as the destination. Each drain sends one data type. To write several data types to one bucket, create one drain per data type. The drains can share a URL, because every object key puts `schema=<schema>` right after the prefix. See [Data types](#data-types) and [File structure](#file-structure).

  Set these fields:
  - **URL**: The `s3://<bucket-name>/<prefix>` path where Vercel writes objects. This is the same value as the API field `endpoint` and the CLI option `--url`.
  - **Encoding**: `json` or `ndjson`. Defaults to `json`. See [Encoding](#encoding).
  - **Compression**: `gzip` or `none`. Defaults to `gzip`, or `none` for Audit Log drains. See [Compression](#compression).
  - **Region**: The AWS region of the bucket.
  - **Role ARN**: The IAM role that Vercel assumes to write objects.
  - **Encryption**: Set it only when the bucket default encryption is SSE-KMS or DSSE-KMS. See [Server-side encryption](#server-side-encryption).
  - **KMS key ARN**: The full key ARN when the bucket uses SSE-KMS or DSSE-KMS with a customer managed key. Without it, S3 encrypts with the AWS managed `aws/s3` key, not the bucket default key.
  - **Object ACL**: Set it only when the bucket requires a canned ACL for object uploads. See [Object ACL](#object-acl).
  **Encryption**, **KMS key ARN**, and **Object ACL** are under **Advanced options**. Leave **Advanced options** off unless your bucket configuration requires extra S3 headers.

  To create the drain from your terminal instead, run `vercel drains create` with an `s3://` URL:
  ```bash filename="terminal"
  vercel drains create --name app-logs-archive --type logs --url s3://my-bucket/drain-data --region us-east-1 --role-arn arn:aws:iam::123456789012:role/vercel-drains
  ```
  See [`vercel drains`](/docs/cli/drains#send-data-to-amazon-s3) for every S3 option.

- ### Test the drain
  Run a test delivery from the Drains page to verify the IAM role, external ID, region, and object write permissions.

  If a test delivery fails, Vercel shows the complete AWS response, including the AWS request ID when AWS returns one. Use the request ID and test timestamp to find the failed request in AWS CloudTrail and debug permission errors.

> **💡 Note:** Vercel does not manage lifecycle policies for your S3 bucket. Configure S3
> lifecycle rules, retention, and storage class transitions in AWS based on your
> compliance and cost requirements.

## Data types

An S3 drain can send any of the following data types. The data type sets the `schema` and `version` segments of each [object key](#file-structure):

| Data type      | Schema name      | Version       | Event reference                                                   |
| -------------- | ---------------- | ------------- | ----------------------------------------------------------------- |
| Logs           | `log`            | `v1`          | [Logs reference](/docs/drains/reference/logs)                     |
| Traces         | `trace`          | `v1`          | [Traces reference](/docs/drains/reference/traces)                 |
| Web Analytics  | `analytics`      | `v2`          | [Analytics reference](/docs/drains/reference/analytics)           |
| Speed Insights | `speed_insights` | `v1`          | [Speed Insights reference](/docs/drains/reference/speed-insights) |
| AI Gateway     | `ai_gateway`     | `otelv1`      | [AI Gateway trace drains](/docs/ai-gateway/observability-and-spend/trace-drains) |
| Connect        | `connect`        | `v1`          | [Connect events reference](/docs/connect/observability#events-reference) |
| Audit Logs     | `audit_log`      | `v1`          | [Audit Log Drains schema](/docs/drains/reference/audit-logs#audit-log-schema) |

Audit Log drains write one event per object. Every other data type batches events, up to about 5 MB per object before compression. Most objects are smaller, and a low-volume drain writes many small objects. The 5 MB size is a target, not a hard limit. Vercel writes an event larger than 5 MB in an object of its own.

New AI Gateway drains write `otelv1` OpenTelemetry traces. AI Gateway drains created earlier can write the older `v1` request events. Create AI Gateway drains in the dashboard, not with the CLI.

Each object holds events of one data type, one schema version, and one UTC day.

S3 drains write Audit Logs in the `v1` format only. The Splunk, Datadog, and Panther Audit Log formats apply only to those destinations.

## Configuration reference

The S3 destination setup accepts the following values. Advanced options are optional.

| Field                  | Description                                      | Example                                                       |
| ---------------------- | ------------------------------------------------ | ------------------------------------------------------------- |
| `endpoint`             | S3 bucket path where Vercel writes drain objects | `s3://<bucket-name>/drain-data`                               |
| `encoding`             | Object body format                               | `json` or `ndjson`                                            |
| `compression`          | Object body compression                          | `none` or `gzip`                                              |
| `fileStructure`        | Object key layout. `hive` is the only value      | `hive`                                                        |
| `roleArn`              | IAM role ARN Vercel assumes to write objects     | `arn:aws:iam::<your-aws-account-id>:role/vercel-drain-writer` |
| `region`               | AWS region where the S3 bucket is located        | `<aws-region>`                                                |
| `serverSideEncryption` | Advanced option for SSE-KMS or DSSE-KMS buckets  | `aws:kms` or `aws:kms:dsse`                                   |
| `kmsKeyId`             | Full KMS key ARN for SSE-KMS or DSSE-KMS         | `arn:aws:kms:<aws-region>:<key-account-id>:key/<kms-key-id>`  |
| `objectAcl`            | Advanced option for buckets that require an ACL  | `bucket-owner-full-control`                                   |

### Endpoint and region

Create or choose an S3 bucket in AWS, then decide whether Vercel writes drain objects at the bucket root or under a prefix.

Use one of these `endpoint` formats:

```txt
s3://<bucket-name>
s3://<bucket-name>/drain-data
```

Set `region` to the AWS region where the bucket is located. Vercel writes all of the drain's objects to that bucket.

### Encoding

The `encoding` value sets the object body format, its `Content-Type`, and its file extension:

| `encoding` | Object body                                                                                                                  | `Content-Type`         | Extension |
| ---------- | ---------------------------------------------------------------------------------------------------------------------------- | ---------------------- | --------- |
| `json`     | One compact JSON array of events, even when the object holds one event. Audit Log objects hold one compact JSON object instead | `application/json`     | `.json`   |
| `ndjson`   | One JSON event per line. Each line ends with a newline                                                                       | `application/x-ndjson` | `.jsonl`  |

Use `ndjson` for drain data that you query with Amazon Athena, Apache Hive, Trino, or Apache Spark. Athena's JSON SerDe and other Hive-style readers read one JSON object per line, so they can't read the top-level array of a `json`-encoded file as rows.

### Compression

New S3 drains use `gzip`, except Audit Log drains, which use `none`. Both values work for every data type.

Set `compression` to `gzip` to gzip each object body. Gzipped objects have the `Content-Encoding: gzip` header, and their keys end in `.gz`, such as `.json.gz` or `.jsonl.gz`. Set `compression` to `none` to write uncompressed objects.

If you change `compression` on an existing drain, the keys of new objects change. Update S3 event notifications, lifecycle rules, and other tools that filter on `.json` or `.jsonl`.

## File structure

S3 object bodies use the event schema of the drain's data type. [Data types](#data-types) links the event reference for each data type.

Vercel uses Hive-style partition paths so analytics and archive tools can query drain data by schema, version, and event date. Normal objects use this key shape:

```txt
<prefix>/schema=<schema>/version=<version>/year=YYYY/month=MM/day=DD/<timestamp>_<id>.<ext>
```

Test objects use this key shape:

```txt
<prefix>/_test/schema=<schema>/version=<version>/year=YYYY/month=MM/day=DD/<timestamp>_<id>.<ext>
```

Test deliveries use a separate `_test/` directory so validation files stay separate from delivered drain data. You can identify and delete test files without changing the production `endpoint` or IAM permissions.

Amazon Athena, Apache Hive, Trino, and Apache Spark skip directories that start with an underscore when they read a table location. A table located at the `endpoint` path doesn't return test objects in these query engines. AWS doesn't document this behavior for AWS Glue crawlers. If an AWS Glue crawler includes the `endpoint` path, add the exclude pattern `_test/**` to the crawler.

Test deliveries previously wrote objects under `test/`. Vercel can't delete objects in your bucket, so delete the `test/` directory when you no longer need it. If an IAM policy or S3 lifecycle rule names `test/`, update it to `_test/`.

Each key segment has the following value:

| Segment                | Value                                                                                                     |
| ---------------------- | --------------------------------------------------------------------------------------------------------- |
| `<prefix>`             | The path in `endpoint`, such as `drain-data`. Keys have no prefix when `endpoint` is the bucket root      |
| `<schema>`             | The schema name of the drain's data type, such as `log` or `audit_log`. See [Data types](#data-types)     |
| `<version>`            | The schema version, such as `v1`                                                                          |
| `year`, `month`, `day` | The UTC date of `<timestamp>`                                                                             |
| `<timestamp>`          | The UTC time of the oldest event in the object, in ISO 8601 format with milliseconds (`YYYY-MM-DDTHH:mm:ss.sssZ`) |
| `<id>`                 | The audit log event ID for Audit Logs. For other data types, a hash of the object's events |
| `<ext>`                | `json` for `json` encoding or `jsonl` for `ndjson` encoding. With `gzip` compression, Vercel appends `.gz` |

For example, a log drain with the endpoint `s3://<bucket-name>/drain-data`, `ndjson` encoding, and `gzip` compression writes objects with keys like this:

```txt
drain-data/schema=log/version=v1/year=2026/month=11/day=25/2026-11-25T14:03:07.512Z_<id>.jsonl.gz
```

## Advanced options

Advanced options map to optional Amazon S3 `PutObject` headers. Leave them unset unless your bucket configuration requires Vercel to send those headers.

### Server-side encryption

Amazon S3 encrypts new objects with SSE-S3 by default. For more information, see [Amazon S3 default encryption](https://docs.aws.amazon.com/AmazonS3/latest/userguide/default-bucket-encryption.html).

For buckets that use the default SSE-S3 encryption, don't set **Encryption**. Set **Encryption** only when the bucket uses SSE-KMS or DSSE-KMS.

Choose the `serverSideEncryption` value that matches the bucket default encryption:

| S3 bucket default encryption                              | Vercel `serverSideEncryption` |
| --------------------------------------------------------- | ----------------------------- |
| Server-side encryption with Amazon S3 managed keys (SSE-S3) | `AES256`                    |
| Server-side encryption with AWS KMS keys (SSE-KMS)        | `aws:kms`                     |
| Dual-layer server-side encryption with AWS KMS keys (DSSE-KMS) | `aws:kms:dsse`             |

For SSE-KMS or DSSE-KMS with a customer managed key, set `kmsKeyId` to the full KMS key ARN, such as `arn:aws:kms:<aws-region>:<key-account-id>:key/1234abcd-12ab-34cd-56ef-1234567890ab`. The key ID at the end of the ARN is either a UUID or a multi-Region key ID that starts with `mrk-`. Alias ARNs (`alias/<alias-name>`) and bare key IDs aren't accepted. Match the key region to `region`, and match the key partition to `roleArn`. The key account can differ from the role account. Without `kmsKeyId`, S3 encrypts objects with the AWS managed `aws/s3` key, not the bucket default key. Add the IAM and key policy permissions above when the key is customer managed.

S3 Bucket Keys are not supported for DSSE-KMS. DSSE-KMS can also increase AWS KMS request costs compared to SSE-KMS.

### Object ACL

For buckets that use the default Object Ownership setting, leave **Object ACL** set to **None**. Amazon S3 disables ACLs by default for new buckets and uses policies for access control. For more information, see [Amazon S3 Object Ownership](https://docs.aws.amazon.com/AmazonS3/latest/userguide/about-object-ownership.html).

Set **Object ACL** only when your bucket configuration requires a canned ACL on object uploads. If you set **Object ACL**, add `s3:PutObjectAcl` to the IAM permissions policy for the same S3 resource.

## Troubleshooting

If the drain test fails with an STS error, check that your IAM role trust policy uses the Vercel S3 drain writer role ARN `arn:aws:iam::977805900156:role/vercel-drains-s3-writer` and the `sts:ExternalId` value `vercel-team:<your-team-id>`.

If the drain test fails with an S3 `AccessDenied` error that says no identity-based policy allows `s3:PutObject`, check that the S3 permissions policy is attached to the same IAM role used as `roleArn` in Vercel. Also check that the policy resource matches the configured `endpoint`.

If the drain test fails for an `endpoint` without a prefix, such as `s3://<bucket-name>`, check that the S3 permissions policy allows `arn:aws:s3:::<bucket-name>/*`. Test deliveries write under `_test/`, so policies scoped only to another prefix won't match test objects.

If objects are encrypted with the AWS managed `aws/s3` key, set `kmsKeyId`. S3 uses `aws/s3` when the drain sends SSE-KMS or DSSE-KMS without a key ARN. S3 does not use the bucket default key in that case.

If saving or testing the drain fails with `S3 delivery KMS key ID requires aws:kms or aws:kms:dsse encryption`, set **Encryption** to SSE-KMS or DSSE-KMS. Vercel treats a `kmsKeyId` sent without `serverSideEncryption` as SSE-S3, which doesn't use a KMS key.

If saving or testing the drain fails with `Invalid S3 delivery KMS key ID`, check that `kmsKeyId` is a full KMS key ARN with a UUID or `mrk-` key ID. Also check that the key region matches `region` and the key partition matches `roleArn`.

If the drain test fails with an AWS KMS error for a customer managed AWS KMS key, check `kmsKeyId`, the IAM role policy, and the key policy. `Resource` in the IAM policy must be the key ARN. `kms:CallerAccount` must be the role account. If the key is in another account, add the key policy statement in that account.

## More resources

- [Drains overview](/docs/drains)
- [Audit Log Drains reference](/docs/drains/reference/audit-logs)
- [Configure Drains](/docs/drains/using-drains)
- [Audit Logs](/docs/audit-log)

## Search the docs from your terminal

Search the Vercel docs and read pages as Markdown with the Vercel CLI. No login required.

```bash
# Find docs pages by keyword
npx vercel@latest docs search "environment variables"
npx vercel@latest docs search "function timeout"

# Print a docs page as Markdown, by path or URL
npx vercel@latest docs inspect <page>
```

## Search guides from your terminal

Search the Knowledge Base and read guides as Markdown with the Vercel CLI. No login required.

```bash
# Find guides by keyword
npx vercel@latest kb search "rewrites and redirects"
npx vercel@latest kb search "AI SDK streaming"

# Show the latest guides
npx vercel@latest kb

# Print a guide as Markdown, by slug or URL
npx vercel@latest kb inspect <guide>
```

---

[View full sitemap](/docs/sitemap)


If you encounter incorrect information, can’t find what you need, need a capability Vercel doesn’t currently offer, or have any other feedback to report, please do it by following the instructions at https://vercel.com/feedback.md.
