如何通过AWS Jupyter Notebook查询(Postgres)RDS数据库?

问题描述 投票:1回答:1

我正在尝试通过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
python python-3.x amazon-web-services boto3 boto
1个回答
0
投票

最后,它比我想象的要简单得多,没什么花哨或具体的。它基本上是我以前访问我的一个本地数据库时使用的解决方案。只需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()
© www.soinside.com 2019 - 2024. All rights reserved.