> For the complete documentation index, see [llms.txt](https://docs.soda.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.soda.io/soda-documentation/reference/data-source-reference-for-soda-core/amazon-athena.md).

# Athena

Access configuration details to connect Soda to an Amazon Athena data source.

### Connection configuration reference

Install the following package:

```bash
pip install soda-athena>4
```

#### Data source YAML

**Create the config file:**

```shellscript
soda data-source create -f ds_config.yml
```

The data source configuration YAML should look like the following:

{% code title="ds\_config.yml" %}

```yaml
type: athena
name: my_athena
connection:
  catalog: ${env.ATHENA_CATALOG}
  access_key_id: ${env.ATHENA_ACCESS_KEY_ID}
  secret_access_key: ${env.ATHENA_SECRET_ACCESS_KEY}
  staging_dir: ${env.ATHENA_STAGING_DIR} ## e.g., s3://my-company-athena-staging/query-results/
  region_name: ${env.ATHENA_REGION}
  work_group: ${env.ATHENA_WOKRGROUP}
#  role_arn: <my_role_arn>
#  profile_name: <my_aws_profile>
#  session_token: <my_session_token>
```

{% endcode %}

#### Connection test

Test the data source connection:

```bash
soda data-source test -ds ds_config.yml
```

***

## Required permissions

The IAM principal (user or role) used by Soda requires **both** IAM Policy permissions **and** AWS Lake Formation permissions. Lake Formation permissions take precedence, even `AdministratorAccess` in IAM Policy will not allow table access if Lake Formation permissions are not also granted.

### **1. Lake Formation permissions**

In addition to the IAM Policy in the following section, grant the following Lake Formation permissions to the principal via the **AWS Console** → **Lake Formation** → **Data permissions**, or via CLI:

```bash
# Grant SELECT and DESCRIBE on source tables
aws lakeformation grant-permissions \
  --principal DataLakePrincipalIdentifier="arn:aws:iam::<account-id>:user/<soda-user>" \
  --permissions "SELECT" "DESCRIBE" \
  --resource '{"Table": {"DatabaseName": "<database>", "TableWildcard": {}}}'

# Grant DESCRIBE on the source database
aws lakeformation grant-permissions \
  --principal DataLakePrincipalIdentifier="arn:aws:iam::<account-id>:user/<soda-user>" \
  --permissions "DESCRIBE" \
  --resource '{"Database": {"Name": "<database>"}}'
```

{% hint style="info" %}
**Tip:** Lake Formation permissions always override IAM; ensure both are configured correctly.

If you see errors like `User is not authorized to perform: lakeformation:GetDataAccess`, check that Lake Formation `SELECT` and `DESCRIBE` permissions are granted for the relevant database and tables.
{% endhint %}

{% hint style="info" %}
**AWS terminology note:** In AWS Glue and Lake Formation, "Database" is equivalent to "Schema" in Athena SQL. Both refer to a logical grouping of tables.
{% endhint %}

#### **Additional Lake Formation permissions for Diagnostics Warehouse**

### **2. IAM Policy permissions**

```json
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Sid": "AthenaReadOnlyAccessforSoda",
      "Effect": "Allow",
      "Action": [
        "athena:StartQueryExecution",
        "athena:GetQueryExecution",
        "athena:BatchGetQueryExecution",
        "athena:GetQueryResults",
        "athena:GetQueryResultsStream",
        "athena:ListQueryExecutions",
        "athena:ListWorkGroups",
        "athena:GetWorkGroup",
        "athena:ListDataCatalogs",
        "athena:GetDataCatalog",
        "athena:ListDatabases",
        "athena:GetDatabase",
        "athena:ListTableMetadata",
        "athena:GetTableMetadata",
        "athena:StopQueryExecution"
      ],
      "Resource": "*"
    },
    {
      "Sid": "GlueReadOnlyAccessforSoda",
      "Effect": "Allow",
      "Action": [
        "glue:GetDatabase",
        "glue:GetDatabases",
        "glue:GetTable",
        "glue:GetTables",
        "glue:GetPartition",
        "glue:GetPartitions",
        "glue:GetUserDefinedFunctions",
        "glue:GetCrawler",
        "glue:GetCrawlers",
        "glue:GetCatalogImportStatus",
        "glue:GetDataCatalogEncryptionSettings",
        "glue:GetSchema",
        "glue:GetSchemaVersion",
        "glue:GetSchemaVersionsDiff",
        "glue:ListSchemas",
        "glue:ListTables",
        "glue:ListCrawlers"
      ],
      "Resource": "*"
    },
    {
      "Sid": "S3StagingBucketAccess",
      "Effect": "Allow",
      "Action": [
        "s3:GetBucketLocation",
        "s3:ListBucket",
        "s3:ListBucketMultipartUploads"
      ],
      "Resource": "arn:aws:s3:::<your-staging-bucket>"
    },
    {
      "Sid": "S3StagingObjectAccess",
      "Effect": "Allow",
      "Action": [
        "s3:GetObject",
        "s3:PutObject",
        "s3:AbortMultipartUpload",
        "s3:ListMultipartUploadParts"
      ],
      "Resource": "arn:aws:s3:::<your-staging-bucket>/<staging-prefix>/*"
    },
    {
      "Effect": "Allow",
      "Action": "lakeformation:GetDataAccess",
      "Resource": "*"
    }
  ]
}
```

{% hint style="warning" %}
**Note on `glue:GetDatabases`:** This permission is required for schema discovery (listing available schemas/databases). Without it, Soda can access tables but **cannot enumerate schemas**.
{% endhint %}

{% hint style="info" %}
**Note on staging bucket:** Athena writes all query results to the `staging_dir` configured in the connection. The Soda IAM principal must have `PutObject` on that location. This is the only location where Soda writes data.
{% endhint %}

#### **Additional IAM Policy permissions for Diagnostics Warehouse**

<br>

***

{% hint style="info" %}
You are **not logged in to Soda** and are viewing the default public documentation. Learn more about [Licensing & documentation access](/soda-documentation/reference/documentation-access-and-licensing.md).
{% endhint %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.soda.io/soda-documentation/reference/data-source-reference-for-soda-core/amazon-athena.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
