简体   繁体   中英

aws localstack redshift connection issue using psycopg2

Using localstack for mocking AWS services. Was trying to connect to local redshift instance using psycopg2. But connection timesout. Connection using boto3 is successfully done.

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)

Output:

{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

Please provide input on what is issue or how to debug this.

I was just looking around for how to connect to localstack's redshift server as well. According to this github issue it looks like it's not really a full redshift server and connecting that way isn't currently possible (as of March 2017 and apparently this is still the case anyways): https://github.com/localstack/localstack/issues/28

Basic support for Redshift is added in #29 . Note that the mock functionality only covers the basic Redshift API methods (a subset of https://docs.aws.amazon.com/redshift/latest/APIReference/ ). The actual query capabilities (ie, accessing Redshift via JDBC) are not supported here (at this stage it is not feasible to mock the entire query engine).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM