# DuckDB and S3

ARNscope has DuckDB built in. Right-click a Parquet, CSV or JSON file (or a folder of them) in the S3 browser, choose **Query with DuckDB**, and you get a SQL console that already reads S3 with the AWS profile you are browsing with. You don't install an extension, write `CREATE SECRET`, run `aws sso login` by hand or look up the bucket's region.

The console is read-only, and nothing runs until you press **Run**.

## Open a DuckDB console

| From | What opens |
| --- | --- |
| **S3**, right-click a file (`.parquet`, `.csv`, `.tsv`, `.json`, `.jsonl`, `.ndjson`, also gzip or Zstandard compressed) → **Query with DuckDB** | The profile's console, with `SELECT * FROM 's3://bucket/path/file' LIMIT 100;` as a draft |
| **S3**, right-click a folder → **Query with DuckDB** | The profile's console, with a draft over every Parquet file below the folder (`**/*.parquet`) |
| **S3**, right-click an empty part of the file list → **Query this folder with DuckDB** | The same for the open folder, with a draft over its most common readable file type, for example `*.csv.gz` |
| **S3**, a Parquet preview → **Open in DuckDB console** | A console for that file |
| **RDS**, **Add database connection** (+) → **Engine: DuckDB** | Choose the **Source** and the **AWS profile**, then **Save and connect** (saved under **DuckDB**, needs a name) or **Open without saving** |

The console opens on the **Databases** page, under **DuckDB**. There is one unsaved console per profile: a second **Query with DuckDB** with the same profile adds its draft to the console that is already open. Edit the draft and press **Run** (⌘↵). Folders and folder globs work as in DuckDB: `*` matches within one folder, `**` crosses folders.

The S3 browser does not offer DuckDB in Trash or in search results.

### A bucket from another profile

A bucket can be open through a different profile from the one ARNscope is on, for example after **⌘P** found it in another account. DuckDB reads S3 with one profile, so **Query with DuckDB** there first asks **Switch to *profile*?**: it names the bucket, the profile it is open through and the profile ARNscope is on. **Switch and open** switches the whole app to the bucket's profile and opens the console; **Cancel** opens nothing.

Tick **Always switch for this bucket** to skip the question for that bucket next time. The buckets that switch without asking are listed in **Settings → Resources from another account → DuckDB from S3**, where you can forget one or all of them.

### Sources

| Source | What it is |
| --- | --- |
| **In-memory** | A session for S3 files that starts empty each time. Saved, it keeps only its AWS profile. |
| **Local .duckdb file** | A DuckDB database file on this Mac, opened read-only, so the file can't change. With an AWS profile it can also read S3; with **None** it reads the file only. |
| **MotherDuck** | Coming soon. Not available yet. |

### What the console can read

The console header shows the **AWS profile** and its region. The console reads **whatever that profile's IAM permissions allow**: any bucket, in any region, that the profile can list and read. ARNscope keeps no bucket list of its own, so there is nothing to add before you query another bucket; name its `s3://` path and press **Run**.

For least privilege, use a profile with a **read-only role** (for example one limited to `s3:ListBucket`, `s3:GetObject` and `s3:GetBucketLocation` on the buckets you need). A bucket the profile can't read fails with S3's own error.

The session itself can't write, local files on your Mac stay blocked (except a `.duckdb` file you opened as the source), and network traffic goes only to AWS S3 endpoints (see [Read-only by construction](#read-only-by-construction)).

## See what a query will read

Before you run, a strip above the results shows what the `s3://` paths in your query match:

> Will read up to **51 files · 9.1 MB** · bucket in **us-east-2** · Parquet, so DuckDB usually reads less

ARNscope counts this from the bucket listing (`ListObjectsV2` under the path's fixed prefix), so it is exact for the files and the most the query can read. DuckDB often reads less: from Parquet it fetches only the columns and row groups it needs.

The strip turns amber when:

- **No files match** the path. Check the path or the file extension.
- The bucket is in **another region** than the one the app is set to. ARNscope reads each bucket in its own region, so this works; expect slower reads.
- The read is **large**: more than **1 GB** or **10,000 files**. **Run** then asks once, in a **Confirm a large read** bar, before it starts.

A listing stops at 100,000 keys and then says "at least". If the preview can't list (a typo being fixed, a signed-out profile), it says why and never blocks the run.

## Signed in with your profile

ARNscope gets the profile's credentials with the AWS SDK, the same way every other page does: IAM Identity Center (SSO), assume-role, MFA and `credential_process` profiles all work. DuckDB's own credential chain does not read SSO profiles; ARNscope does it for DuckDB.

DuckDB gets **temporary keys**, as temporary secrets. Before a query runs, ARNscope gives each bucket it names a secret of its own in that bucket's region (from `GetBucketLocation`), so buckets in different regions work in one query. If the profile may not read a bucket's region, ARNscope uses the profile's region and S3's own error says what is wrong. ARNscope renews the keys before they expire. The keys live in the session's memory only: they are never written to disk, never kept in query history and never logged.

If your SSO sign-in has expired, the console says so and offers **Sign in to *profile***, which runs `aws sso login` in your browser. Your query and its results stay where they are.

## Read-only by construction

A DuckDB session in ARNscope has no write mode. Three layers keep it that way:

1. **ARNscope's statement check.** A statement must start with `SELECT`, `WITH`, `FROM`, `VALUES`, `TABLE`, `DESCRIBE`, `SUMMARIZE`, `SHOW`, `PIVOT`, `UNPIVOT` or `EXPLAIN` (not `EXPLAIN ANALYZE`, which runs the statement). Functions that run SQL from text (`query`, `query_table`, `json_execute_serialized_sql`) and checkpoints are refused. So are `COPY`, `EXPORT`, `ATTACH`, `INSTALL`, `LOAD`, `SET`, `PRAGMA`, `CALL`, `CREATE SECRET` and every DDL or DML statement.
2. **DuckDB's own parser.** Each statement is then parsed by DuckDB (parsed only, nothing runs) and must come back as exactly one query. If ARNscope's check and DuckDB's parser would read the text differently, it is refused rather than guessed at.
3. **A locked session.** When the session opens, ARNscope lets DuckDB read `s3://` paths only (plus the `.duckdb` file it opened), turns off every other file and network access, and locks the configuration. After that no statement can read a local file, reach an `https://` URL, load an extension or change a setting.

On top of that, **network traffic goes only to AWS S3 endpoints.** Every request DuckDB makes goes through a small proxy inside ARNscope that opens TLS connections on port 443 only to S3's own host names (`bucket.s3.region.amazonaws.com` and `s3.region.amazonaws.com`). Other AWS services, other hosts, IP addresses, other ports and plain HTTP are refused before they leave your Mac. TLS stays end to end between DuckDB and S3.

Which buckets the session reads is up to the profile's IAM permissions, not ARNscope.

S3 paths are written out in full, as plain paths. A URL with `?…` settings or `..`, or a path built from other values, is refused: ARNscope sets the region, endpoint and credentials itself. When a statement is refused, the console says why in one line ("Not run: COPY … TO writes a file, and this DuckDB tab is read-only.") and **Why?** shows the check's own words. Nothing was sent to S3.

The DuckDB extension that reads S3 (`httpfs`) ships inside ARNscope, for Apple silicon and Intel builds alike. ARNscope never downloads an extension at run time.

## Results and export

- Results show up to **1,000 rows** or **1 MiB**. A single `SELECT` without `LIMIT` gets `LIMIT 500`.
- A script runs up to 100 statements. **Cancel** stops a running query.
- **Export** → **Export CSV…** or **Export Parquet…** saves the rows shown to a file you pick on this Mac. Nothing is written to S3.
- Query history and the console text are kept on this Mac. Statements that name a key, secret or token lose their string values before they are saved. See [SQL consoles](https://arnscope.com/docs/sql-consoles).

## Saved DuckDB connections

A DuckDB console you open from the S3 browser, or with **Open without saving**, is not saved: it is listed under **DuckDB** as "not saved" and goes when you close it. Its SQL and run history stay under [SQL consoles](https://arnscope.com/docs/sql-consoles).

To keep a console, save it as a connection:

- **In the console:** **Save** in the header (on a console that isn't saved yet) asks for a **Name**, then **Save connection**. The console re-opens as the saved connection, and its draft, run history and catalog cache move with it, so [SQL consoles](https://arnscope.com/docs/sql-consoles) shows one row for it, not two.
- **In Add database connection:** **Engine: DuckDB**, a name, the source and the AWS profile, then **Save and connect**.

Saved DuckDB connections are listed under **DuckDB** on the **Databases** page, marked "saved", in every profile and region. Selecting one shows its database, its profile and **Connect**. Its row menu (⋮) has **Edit**, which changes its name, source and profile (applied at the next connect), and **Delete connection**, which asks first under the row; the console's SQL stays under SQL consoles.

A saved DuckDB connection stores only its source (in-memory, or the `.duckdb` file's path) and the AWS profile's name. It never stores credentials, keys or tokens: ARNscope gets fresh temporary keys for the profile each time it connects. Connections saved before this change, with a list of buckets, keep their profile and read whatever it allows. Saved connections stay on this Mac.

## Permissions

| What | Actions |
| --- | --- |
| Scan preview and globs | `s3:ListBucket` on the bucket |
| Reading files | `s3:GetObject` on the files |
| Each bucket's region, the first time a session reads it | `s3:GetBucketLocation` |
| Files encrypted with a customer-managed KMS key | `kms:Decrypt` on that key |

These are the profile's own permissions: the console can read every bucket they allow. Give the profile a read-only role to keep it narrow.

Reading from S3 incurs the usual S3 request and data transfer charges. There is no per-query or per-terabyte charge from ARNscope or AWS beyond those.

## Limitations

- **No writes.** No `COPY … TO`, no `CREATE TABLE`, no writing to S3 or to the `.duckdb` file. Export the rows shown instead.
- **MotherDuck is not supported yet.** It shows as "Coming soon" under **Source**.
- **No Athena or Glue tables.** ARNscope reads files by their S3 path; it does not read the Glue Data Catalog, Iceberg tables or S3 Tables.
- **S3 and local `.duckdb` files only.** HTTPS, Google Cloud Storage and Azure URLs can't be reached from a session, and neither can other local files.
- **A path that matches no files fails in DuckDB.** The scan preview warns before you run. [Investigate](https://arnscope.com/docs/investigate) questions skip the hours that have no files for you.
- **One profile per console.** To read with another profile, open a console for it. Querying a bucket that is open through another profile switches the whole app to that profile, after asking.
- **No bucket list of its own.** ARNscope does not narrow what a profile may read; use a read-only role for that.
- **Results are capped** at 1,000 rows or 1 MiB, and an export holds the rows shown.
- A `PIVOT` needs an explicit `IN` list in a read-only session.
- Apple silicon and Intel Macs are both supported. DuckDB consoles need the desktop app; the web preview has sample data only.

Something you'd like DuckDB to read? Write to [hello@arnscope.com](mailto:hello@arnscope.com).

Source: https://arnscope.com/docs/duckdb-s3
