2

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.

shrishinde
  • 3,219
  • 1
  • 20
  • 31

1 Answers1

2

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 (i.e., accessing Redshift via JDBC) are not supported here (at this stage it is not feasible to mock the entire query engine).

adavea
  • 1,535
  • 1
  • 19
  • 25
  • As of January 2023, Localstack emulates Redshift, ie. the query engine itself, by spinning up a plain PostgreSQL server locally. – schiavuzzi Jan 23 '23 at 23:11