# Amazon Redshift Spectrum Data Source

You can create an Amazon Redshift Spectrum data source using the [Immuta CLI](#create-a-data-source-using-the-immuta-cli) or the [Immuta V2 API](#create-a-data-source-using-the-immuta-v2-api).

## Requirements

* The [<mark style="color:blue;">`enable_case_sensitive_identifier`</mark> <mark style="color:blue;">parameter</mark>](https://docs.aws.amazon.com/redshift/latest/dg/r_enable_case_sensitive_identifier.html) must be set to `false` (default setting) for your Redshift cluster.
* `CREATE_DATA_SOURCE` Immuta permission
* The Redshift user registering data sources must have the following privileges on all securables:
  * `USAGE` on all schemas with registered data sources
  * `SELECT` on all tables within those schemas

## Create a data source using the Immuta CLI

```yaml
connectionKey: redshift
connection:
  hostname: your-redshift-cluster.djie25k.us-east-1.redshift.amazonaws.com
  port: 5439
  ssl: true
  database: your_database_with_external_schema
  username: awsuser
  password: your_password
  handler: Redshift
  schema: external_schema
nameTemplate:
  dataSourceFormat: <Tablename>
  schemaFormat: <schema>
  tableFormat: <tablename>
  schemaProjectNameFormat: <Schema>
  nativeSchemaFormat: <schema>_immuta
  nativeViewFormat: <tablename>
sources:
  - all: true
```

1. Copy the snippet above and save it as a YAML file. Replace the configuration values with your own, where
   1. **hostname** is the URL of your Redshift account.
   2. **database** is the name of the [existing or new database](#setup-the-immuta-database) that the Immuta system user will manage and store metadata in.
   3. **username** and **password** are the credentials for the system account that can act on Redshift objects and configure the integration.
   4. **schema** is the name of the external schema in the **database.**
2. Run `immuta datasource save <filepath> [--wait int] [--dryRun]`, referencing the file you just created. The options you can specify include
   * `-d` or `--dryRun`: No updates will actually be made to the data source(s).
   * `-h` or `--help`: Get more information about the command.
   * `-w` or `--wait int`: Specify how long to wait for data source creation.

For additional configuration options, see the connection object details for Redshift Spectrum data sources on the [Create a data source guide](https://documentation.immuta.com/SaaS/developer-guides/api-intro/immuta-v2-api/data-source#connection-object).

{% hint style="warning" %}
**Avoid schema name conflicts**

Your `nativeSchemaFormat` must contain `_immuta` to avoid schema name conflicts.
{% endhint %}

## Create a data source using the Immuta V2 API

```bash
curl -X 'POST' \
  'https://www.organization.immuta.com/api/v2/data' \
  -H 'accept: application/json' \
  -H 'Content-Type: application/json' \
  -H 'Authorization: Bearer b64dbdcd29e24ae88a5b3ce0507df019' \
  -d '{
  "connectionKey": "redshift",
  "connection": {
      "hostname": "your-redshift-cluster.djie25k.us-east-1.redshift.amazonaws.com",
      "port": "5439",
      "ssl": true,
      "database": "your_database_with_external_schema",
      "username": "awsuser",
      "password": "your_password",
      "handler": "Redshift",
      "schema": "external_schema"
  },
  "nameTemplate": {
      "dataSourceFormat": "<Tablename>",
      "schemaFormat": "<schema>",
      "tableFormat": "<tablename>",
      "schemaProjectNameFormat": "<Schema>",
      "nativeSchemaFormat": "<schema>_immuta",
      "nativeViewFormat": "<tablename>"
    },
    "sources": [
    {
      "all": true
    }
    ]
    }'
```

1. Copy the request example. The example provided uses JSON format, but the request also accepts YAML.
2. Replace the **Immuta URL** and [**API key**](https://documentation.immuta.com/SaaS/developer-guides/api-intro/integrations-api/getting-started#authenticate-with-the-api) with your own.
3. Change the **config** values to your own, where
   1. **hostname** is the URL of your Redshift account.
   2. **database** is the name of the [existing or new database](#setup-the-immuta-database) that the Immuta system user will manage and store metadata in.
   3. **username** and **password** are the credentials for the system account that can act on Redshift objects and configure the integration.
   4. **schema** is the name of the external schema in the **database.**

{% hint style="warning" %}
**Avoid schema name conflicts**

Your `nativeSchemaFormat` must contain `_immuta` to avoid schema name conflicts.
{% endhint %}

### Path parameters

| Parameter            | Description                                                                                                                   | Required or optional | Default value |
| -------------------- | ----------------------------------------------------------------------------------------------------------------------------- | -------------------- | ------------- |
| **dryRun** `boolean` | If `true`, no updates will actually be made.                                                                                  | Optional             | `false`       |
| **wait** `number`    | The number of seconds to wait for data sources to be created before returning. Anything less than `0` will wait indefinitely. | Optional             | `0`           |

### Body parameters

The request accepts a JSON or YAML payload with the parameters outlined below.

| Parameter                                                                                                                                   | Description                                                                                                                                                                                                                                                                            | Required or optional |
| ------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------- |
| **connectionKey** `string`                                                                                                                  | A key/name to uniquely identify this collection of data sources.                                                                                                                                                                                                                       | Required             |
| [**connection**](https://documentation.immuta.com/SaaS/developer-guides/api-intro/immuta-v2-api/data-source#connection-object) `object`     | Connection information. See the [connection object description](https://documentation.immuta.com/SaaS/developer-guides/api-intro/immuta-v2-api/data-source#connection-object) for attribute details.                                                                                   | Required             |
| [**nameTemplate**](https://documentation.immuta.com/SaaS/developer-guides/api-intro/immuta-v2-api/data-source#nametemplate-object) `object` | A template to override naming conventions. If not provided, system defaults will be used. See the [nameTemplate object description](https://documentation.immuta.com/SaaS/developer-guides/api-intro/immuta-v2-api/data-source#nametemplate-object) for attribute details.             | Optional             |
| [**options**](https://documentation.immuta.com/SaaS/developer-guides/api-intro/immuta-v2-api/data-source#options-object) `object`           | Override options for these data sources. If not provided, system defaults will be used. See the [options object description](https://documentation.immuta.com/SaaS/developer-guides/api-intro/immuta-v2-api/data-source#options-object) for attribute details.                         | Optional             |
| [**owners**](https://documentation.immuta.com/SaaS/developer-guides/api-intro/immuta-v2-api/data-source#owners-object) `object`             | Specify owners for all data sources created. See the [owners object description](https://documentation.immuta.com/SaaS/developer-guides/api-intro/immuta-v2-api/data-source#owners-object) for attribute details.                                                                      | Optional             |
| [**sources**](https://documentation.immuta.com/SaaS/developer-guides/api-intro/immuta-v2-api/data-source#sources-array) `array`             | Configure which data sources are created. If not provided, all objects from the given connection will be created. See the [sources array description](https://documentation.immuta.com/SaaS/developer-guides/api-intro/immuta-v2-api/data-source#sources-array) for attribute details. | Optional             |
