我正在尝试通过python查询RDS(Postgres)数据库,更具体地说是Jupyter笔记本。总的来说,我现在一直在努力的是:
import boto3
client = boto3.client('rds-data')
response = client.execute_sql(
awsSecretStoreArn='string',
database='string',
dbClusterOrInstanceArn='string',
schema='string',
sqlStatements='string'
)
我收到的错误是:
BadRequestException: An error occurred (BadRequestException) when calling the ExecuteSql operation: ERROR: invalid cluster id: arn:aws:rds:us-east-1:839600708595:db:zprime
最后,它比我想象的要简单得多,没什么花哨或具体的。它基本上是我以前访问我的一个本地数据库时使用的解决方案。只需import
为您的数据库类型(Postgres,MySQL等)的特定库,然后连接到它以便通过python执行查询。
我不知道它是否是最好的解决方案,因为通过python进行查询可能比直接进行查询慢得多,但它现在起作用了。
import psycopg2
conn = psycopg2.connect(database = 'database_name',
user = 'user',
password = 'password',
host = 'host',
port = 'port')
cur = conn.cursor()
cur.execute('''
SELECT *
FROM table;
''')
cur.fetchall()