Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a helper function for connecting to Redshift #879

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

atheriel
Copy link
Collaborator

This commit introduces a new odbc::redshift() function intended to help setting up connections to AWS Redshift, especially when using IAM credentials. It generally follows the pattern established with odbc::databricks() and odbc::snowflake().

Note that finding IAM credentials is outsourced to paws.common. Some Redshift ODBC drivers (there are a few of them) can handle AWS profiles or IAM role assumption, and I did have an earlier version of this commit that did this work manually; unfortunately the supported parameters depend not only on the driver, but also the driver version, and it quickly became a mess.

So: using paws.common here allows us to be very driver version-agnostic, and ensures we support as wide a number of IAM setups as possible.

Note that I also refectored some of automatic driver discover for Databricks and Snowflake into its own helper utility so we could use the same logic for Redshift, and fixed some grammar issues in their respective error messages.

Unit tests are included.

Part of #878.

@atheriel
Copy link
Collaborator Author

Test failures seem unrelated.

@simonpcouch
Copy link
Collaborator

Yup, failures are unrelated and addressed in #876! No worries there.

@atheriel atheriel force-pushed the redshift-helper-v2 branch 2 times, most recently from 029888d to 2af0891 Compare January 13, 2025 17:54
@tnederlof
Copy link

This seems to work as expected with this code.

library(odbc)

con <- DBI::dbConnect(
  odbc::redshift(),
  region = "us-east-2",
  clusterId = "tn-demo-cluster",
  database = "demo_db",
  dbuser = "tnederlof"
)

dbListTables(con)

I do need to specify the region otherwise, I get this error: Error occurred while trying to connect: ClusterNotFound: Cluster tn-demo-cluster not found.

This commit introduces a new `odbc::redshift()` function intended to
help setting up connections to AWS Redshift, especially when using IAM
credentials. It generally follows the pattern established with
`odbc::databricks()` and `odbc::snowflake()`.

Note that finding IAM credentials is outsourced to `paws.common`. Some
Redshift ODBC drivers (there are a few of them) can handle AWS profiles
or IAM role assumption, and I did have an earlier version of this commit
that did this work manually; unfortunately the supported parameters
depend not only on the driver, but also the driver version, and it
quickly became a mess.

So: using `paws.common` here allows us to be very driver
version-agnostic, and ensures we support as wide a number of IAM setups
as possible.

Note that I also refectored some of automatic driver discover for
Databricks and Snowflake into its own helper utility so we could use the
same logic for Redshift, and fixed some grammar issues in their
respective error messages.

Unit tests are included.

Signed-off-by: Aaron Jacobs <aaron.jacobs@rstudio.com>
@atheriel
Copy link
Collaborator Author

Some checks are failing due to #882.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants