

# Connect to Athena with the DuckDB extension

Use the **Athena extension for DuckDB** to connect to Athena with DuckDB's `ATTACH` operation and work with your data in a local DuckDB session. With the extension, you can run queries on Athena, create local tables from Athena query results, combine remote and local data, and more, from the same local DuckDB session. Local operations use the resources of your machine. When a query references tables attached from Athena, it runs on Athena and the results stream back to your local session in Apache Arrow format, where you can join them with local files.

The extension is open source under the Apache License, Version 2.0. For the source code, see the [duckdb-athena repository](https://github.com/aws/duckdb-athena) on GitHub.

## Quick start
<a name="connect-with-duckdb-extension-quick-start"></a>

Complete the prerequisites in [Install the extension](connect-with-duckdb-extension-download-and-install.md) first. Start DuckDB locally, then replace the Region, workgroup, database, and table with your values. Registering the repository is a one-time setup, so you do not need to register it again each time you use the extension.

```sql
-- Register the repository and install a compatible extension.
CREATE EXTENSION REPOSITORY aws.amazon.com;
INSTALL athena FROM aws.amazon.com;

-- Load the extension and select a refreshable signing secret.
LOAD athena FROM aws.amazon.com;
CREATE SECRET athena_creds
    (TYPE aws, PROVIDER credential_chain, REGION '{{us-west-2}}', REFRESH 'auto');

-- Attach your workgroup and read an existing table.
ATTACH 'arn:aws:athena' AS ath
    (TYPE athena, Region '{{us-west-2}}',
     WorkGroup '{{my-duckdb-workgroup}}', Secret 'athena_creds');

SELECT * FROM ath.{{my_database}}.{{my_table}} LIMIT 10;
```

## Considerations and limitations
<a name="connect-with-duckdb-extension-considerations"></a>
+ Use a DuckDB workgroup. The extension refuses a workgroup that is not configured for the DuckDB engine when you run `ATTACH`.
+ Athena workgroups are not an external resource type for `SHOW ALL EXTERNAL RESOURCES`. Select your workgroup separately and name it in the `ATTACH` path or `WorkGroup` option.
+ Not all operations performed locally are accepted by Athena. To understand how DuckDB queries executed locally differ from those run on Athena, see [Differences with local DuckDB](connect-with-duckdb-extension-differences.md).