使用 localstack 模拟 AWS 服务。正在尝试使用 psycopg2 连接到本地 redshift 实例。但是连接超时。使用 boto3 连接成功。
client = boto3.client('redshift', endpoint_url='http://127.0.0.1:5439/')
print client.describe_clusters()
con = psycopg2.connect(dbname='test123', host='127.0.0.1', port=5439, user='user', password='password', connect_timeout=10)
输出:
{u'Clusters': [{u'NumberOfNodes': 1, u'AvailabilityZone': 'localhost', u'NodeType': 'ds1.large', u'PubliclyAccessible': True, u'MasterUsername': 'user', u'ClusterParameterGroups': [{u'ParameterGroupName': 'default.redshift-1.0', u'ParameterApplyStatus': 'in-sync'}], u'Encrypted': True, u'ClusterSecurityGroups': [{u'Status': 'active', u'ClusterSecurityGroupName': 'Default'}], u'AllowVersionUpgrade': False, u'VpcSecurityGroups': [], u'ClusterSubnetGroupName': 'testgroup', u'AutomatedSnapshotRetentionPeriod': 1, u'ClusterStatus': 'creating', u'ClusterIdentifier': 'test123', u'DBName': 'test123', u'PreferredMaintenanceWindow': 'Mon:03:00-Mon:03:30', u'ClusterVersion': '1.0'}], 'ResponseMetadata': {'RetryAttempts': 0, 'HTTPStatusCode': 200, 'RequestId': '384ac68d-3775-11df-8963-01868b7c937a', 'HTTPHeaders': {'date': 'Thu, 28 Sep 2017 05:54:46 GMT', 'content-length': '1264', 'content-type': 'text/html; charset=utf-8', 'server': 'amazon.com'}}}
Traceback (most recent call last):
File "/home/shrishinde/PycharmProjects/Test/redshift_test.py", line 46, in <module>
con = psycopg2.connect(dbname='test123', host='127.0.0.1', port=5439, user='user', password='password', connect_timeout=10)
File "/usr/local/lib/python2.7/dist-packages/psycopg2/__init__.py", line 130, in connect
conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
psycopg2.OperationalError: timeout expired
请提供有关问题或如何调试的输入。