【发布时间】:2021-02-03 21:27:57
【问题描述】:
我想使用 python boto3 获取 redshift 中的列名
- 已创建 Redshift 集群
- 向其中插入数据
- 配置的 Secrets Manager
- 配置 SageMaker 笔记本
打开Jupyter Notebook写下如下代码
import boto3
import time
client = boto3.client('redshift-data')
response = client.execute_statement(ClusterIdentifier = "test", Database= "dev", SecretArn= "{SECRET-ARN}",Sql= "SELECT `COLUMN_NAME` FROM `INFORMATION_SCHEMA`.`COLUMNS` WHERE `TABLE_SCHEMA`='dev' AND `TABLE_NAME`='dojoredshift'")
我收到了响应,但里面没有表架构
下面是我用来连接的代码,我超时了
import psycopg2
HOST = 'xx.xx.xx.xx'
PORT = 5439
USER = 'aswuser'
PASSWORD = 'Password1!'
DATABASE = 'dev'
def db_connection():
conn = psycopg2.connect(host=HOST,port=PORT,user=USER,password=PASSWORD,database=DATABASE)
return conn
如何获取ip地址去https://ipinfo.info/html/ip_checker.php
传递您的 redshiftcluster 主机名xx.xx.us-east-1.redshift.amazonaws.com 或者您可以在集群页面本身中看到
我在运行上面的代码时遇到了错误
OperationalError:无法连接到服务器:连接超时 服务器是否在主机“x.xx.xx..xx”上运行并接受 端口 5439 上的 TCP/IP 连接?
【问题讨论】:
-
我关注的创建集群和表的博客。 aws-dojo.com/excercises/excercise19
标签: python amazon-redshift boto3