如何使用Python boto3以红移方式获取列名
我想使用python boto3以红移方式获取列名如何使用Python boto3以红移方式获取列名,python,amazon-redshift,boto3,Python,Amazon Redshift,Boto3,我想使用python boto3以红移方式获取列名 Creaed红移星团 将数据插入其中 配置的机密管理器 配置SageMaker笔记本电脑 打开Jupyter笔记本,写下下面的代码 import boto3 import time client = boto3.client('redshift-data') response = client.execute_statement(ClusterIdentifier = "test", Database= &q
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
将您的主机名传递给redshiftclusterxx.xx.us-east-1.redshift.amazonaws.com
,或者您可以在集群页面中看到
我在运行上述代码时出错
操作错误:无法连接到服务器:连接超时
服务器是否在主机“x.xx.xx..xx”上运行并接受
端口5439上的TCP/IP连接
我修改了代码,并添加了上面的规则
import boto3
import psycopg2
# Credentials can be set using different methodologies. For this test,
# I ran from my local machine which I used cli command "aws configure"
# to set my Access key and secret access key
client = boto3.client(service_name='redshift',
region_name='us-east-1')
#
#Using boto3 to get the Database password instead of hardcoding it in the code
#
cluster_creds = client.get_cluster_credentials(
DbUser='awsuser',
DbName='dev',
ClusterIdentifier='redshift-cluster-1',
AutoCreate=False)
try:
# Database connection below that uses the DbPassword that boto3 returned
conn = psycopg2.connect(
host = 'redshift-cluster-1.cvlywrhztirh.us-east-1.redshift.amazonaws.com',
port = '5439',
user = cluster_creds['DbUser'],
password = cluster_creds['DbPassword'],
database = 'dev'
)
# Verifies that the connection worked
cursor = conn.cursor()
cursor.execute("SELECT VERSION()")
results = cursor.fetchone()
ver = results[0]
if (ver is None):
print("Could not find version")
else:
print("The version is " + ver)
except:
logger.exception('Failed to open database connection.')
print("Failed")
我跟随博客创建集群和表。我也试过了