简体   繁体   中英

how to make a connection to an existing Redshift database using JDBC driver and Boto3 API in Python

I do not know how to write a connection string in Python using Boto3 API to make a jdbc connection to an existing database on AWS Redshift. I am using MobaXterm or putty to make a SSH connection. I have some codes to create the table, but am lost as to how to connect to the Database in Redshift

import boto3

s3client = boto3.client('redshift', config=client-config)

CREATE TABLE pheaapoc_schema.green_201601_csv (
    vendorid varchar(4),
    pickup_ddatetime TIMESTAMP,
    dropoff_datetime TIMESTAMP,

I need to connect to database "dummy" and create a table.

TL;DR; You do not need IAM credentials or boto3 to connect to Redshift. What you need is end_point for the Redshift cluster and redshift credentials and a postgres client using which you can connect.

You can connect to Redshift cluster just the way you connect to any Database (Like MySQL, PostgreSQL or MongoDB). To connect to any database, you need 5 items.

  1. host - (This is nothing but the end point you get from AWS console/Redshift)
  2. username - (Refer again to AWS console/Redshift. Take a look at master username section)
  3. password - (If you created the Redshift, you should know the password for master user)
  4. port number - (5439 for Redshift)
  5. Database - (The default database you created at first)

Refer to the screenshot if it is not intuitive.

What boto3 APIs do?

Boto3 provides APIs using which you can modify your Redshift cluster. For example, it provides APIs to delete your cluster, resize your cluster or take a snapshot of your cluster. They do not involve connection whatsoever.

Screenshots for reference:

终点

AWS控制台

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM