PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Thursday, April 21, 2022

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

 April 21, 2022     amazon-redshift, boto3, connection, jdbc, python     No comments   

Issue

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.


Solution

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:

End point

AWS console



Answered By - nightgaunt
Answer Checked By - Gilberto Lyons (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing