我正在尝试使用以下代码从 EC2 机器连接到 AWS RDS (postgres)。当我从本地计算机运行它并在数据库中创建表时,这非常有效。但是当我从 EC2 运行它时,它会抛出一个错误:
sqlalchemy.exc.OperationalError: (psycopg2.OperationalError) could not connect to server: Connection timed out Is the server running on host "" (IP) and accepting TCP/IP connections on port ?
import csv
import boto3
from io import StringIO
from sqlalchemy import create_engine, MetaData, Table, Column, BigInteger, Date, Integer, String
engine = create_engine('postgresql://<user>:<password>@<host>:<port>/<db>')
table_name = 'checking'
meta = MetaData()
table_name = Table(
table_name, meta,
Column('phone', BigInteger, primary_key = True),
Column('first_name', String),
schema = 'testing'
)
meta.create_all(engine)
我认为 RDS 或 EC2 存在一些权限问题。在 EC2 上,我可以在任何地方访问 HTTP、HTTPS、TCP、SSH。
最佳答案
哦,我对上面的 postgres 访问没有打开。
关于postgresql - 通过 EC2 从 sqlalchemy 连接 AWS RDS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58851567/