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

# Connect to Redshift

> How to connect Atoti DirectQuery to Amazon Redshift using the JDBC driver, covering role and user setup with `USAGE` and `SELECT` privileges, basic authentication via connection string, and IAM credentials from the AWS credentials file

The Atoti DirectQuery Redshift connector uses the [Redshift JDBC driver](https://docs.aws.amazon.com/redshift/latest/mgmt/jdbc20-install.html)
to connect to a database.

## User and role

Connecting DirectQuery to Redshift first requires a user linked to a role with sufficient privileges.
The following actions require a Redshift 'power user' account.

### How to create a role

The AWS [role creation reference](https://docs.aws.amazon.com/redshift/latest/dg/r_CREATE_ROLE.html) describes how to create a role.

### How to grant required privileges to this role

DirectQuery required privileges are:

* `USAGE` privilege on target schema
* `SELECT` privilege on schema queryable objects (tables, views)

The AWS [privilege granting reference](https://docs.aws.amazon.com/redshift/latest/dg/r_GRANT.html) describes how to grant these to the new role.

### How to create a user linked to this role

The last step is to create a user with the following attributes:

* login
* password

The AWS [user management documentation](https://docs.aws.amazon.com/redshift/latest/dg/r_CREATE_USER.html) covers this step.

Then assign the role to the user with a `GRANT ROLE` command.

## Basic authentication connection

Connection is done through [DirectQuery Redshift connector](https://docs.activeviam.com/engine/java-sdk/6.2/directquery/getting_started.md#create-the-database-connector) passing the following minimal properties:

* [JDBC connection string](https://docs.aws.amazon.com/redshift/latest/mgmt/jdbc20-obtain-url.html)
* password

## Authentication connection with AWS IAM credentials

After configuring AWS, the credentials are usually stored into the file `~/.aws/credentials`.
If the location is different, it can be set with the `AWS_CREDENTIAL_PROFILES_FILE` environment variable.

The AWS user needs the AWS permissions `redshift:DescribeClusters` and `redshift:GetClusterCredentials`.

Then only the connection string has to be provided, starting with `jdbc:redshift:iam://`.

For more details, check the [AWS documentation](https://docs.aws.amazon.com/redshift/latest/mgmt/generating-iam-credentials-configure-jdbc-odbc.html).
