Amazon Redshift Connection

The Redshift connection type enables integrations with Redshift.

Authenticating to Amazon Redshift

Authentication may be performed using any of the authentication methods supported by redshift_connector such as via direct credentials, IAM authentication, or using an Identity Provider (IdP) plugin.

Default Connection IDs

The default connection ID is redshift_default.

Configuring the Connection

User

Specify the username to use for authentication with Amazon Redshift.

Password

Specify the password to use for authentication with Amazon Redshift.

Host

Specify the Amazon Redshift hostname.

Database

Specify the Amazon Redshift database name.

Extra

Specify the extra parameters (as json dictionary) that can be used in Amazon Redshift connection. For a complete list of supported parameters please see the documentation for redshift_connector.

When specifying the connection in environment variable you should specify it using URI syntax.

Note that all components of the URI should be URL-encoded.

Examples

Database Authentication

>>> from airflow.models.connection import Connection
>>> import json

>>> c = Connection(
...     conn_type="redshift",
...     extra=json.dumps(
...         {
...             "user": "awsuser",
...             "password": "password",
...             "host": "redshift-cluster-1.123456789.us-west-1.redshift.amazonaws.com",
...             "port": 5439,
...             "database": "dev",
...             "ssl": True,
...             "sslmode": "verify-full",
...         }
...     ),
... )
>>> print(c.get_uri())
redshift://?__extra__=%7B%22user%22%3A+%22awsuser%22%2C+%22password%22%3A+%22password%22%2C+%22host%22%3A+%22redshift-cluster-1.123456789.us-west-1.redshift.amazonaws.com%22%2C+%22port%22%3A+5439%2C+%22database%22%3A+%22dev%22%2C+%22ssl%22%3A+true%2C+%22sslmode%22%3A+%22verify-full%22%7D

IAM Authentication using AWS Profile

>>> from airflow.models.connection import Connection
>>> import json

>>> c = Connection(
...     conn_type="redshift",
...     extra=json.dumps(
...         {
...             "iam": True,
...             "db_user": "awsuser",
...             "database": "dev",
...             "cluster_identifier": "redshift-cluster-1",
...             "profile": "default",
...         }
...     ),
... )
>>> print(c.get_uri())
redshift://?__extra__=%7B%22iam%22%3A+true%2C+%22db_user%22%3A+%22awsuser%22%2C+%22database%22%3A+%22dev%22%2C+%22cluster_identifier%22%3A+%22redshift-cluster-1%22%2C+%22profile%22%3A+%22default%22%7D

Authentication using Okta Identity Provider

>>> from airflow.models.connection import Connection
>>> import json

>>> c = Connection(
...     conn_type="redshift",
...     extra=json.dumps(
...         {
...             "iam": True,
...             "user": "developer@domain.org",
...             "password": "myOktaPassword",
...             "database": "dev",
...             "cluster_identifier": "redshift-cluster-1",
...             "credentials_provider": "OktaCredentialsProvider",
...             "idp_host": "my_idp_host",
...             "app_id": "myAppId",
...             "app_name": "myAppName",
...         }
...     ),
... )
>>> print(c.get_uri())
redshift://?__extra__=%7B%22iam%22%3A+true%2C+%22user%22%3A+%22developer%40domain.org%22%2C+%22password%22%3A+%22myOktaPassword%22%2C+%22database%22%3A+%22dev%22%2C+%22cluster_identifier%22%3A+%22redshift-cluster-1%22%2C+%22credentials_provider%22%3A+%22OktaCredentialsProvider%22%2C+%22idp_host%22%3A+%22my_idp_host%22%2C+%22app_id%22%3A+%22myAppId%22%2C+%22app_name%22%3A+%22myAppName%22%7D

Was this entry helpful?