0

我在我的AWS账户中拥有一个Redshift群集。我能够连接到它的蟒蛇,当我在本地运行脚本,它运行完美的罚款:如何从我的Amazon EC2实例内连接到Amazon Redshift群集

import psycopg2 
con = psycopg2.connect(dbname='some_dbname', host='hostname.us-east-2.redshift.amazonaws.com', port='port#', user='username', password='password') 
    cursor=con.cursor() 
    query = "select * from table;" 
    cursor.execute(query) 
    data = np.array(cursor.fetchall()) 
cursor.close() 
con.commit() 
con.close() 

但是,当我上面的脚本复制到我的EC2实例(亚马逊的Linux AMI),然后再尝试运行它,我得到以下错误:

conn = _connect(dsn, connection_factory=connection_factory, **kwasync) 
psycopg2.OperationalError: could not connect to server: Connection timed out 
    Is the server running on host "hostname.us-east-2.redshift.amazonaws.com" and accepting 
    TCP/IP connections on port port#? 

任何人都可以帮我如何从我的EC2实例连接到我的红移集群?谢谢!

+1

您是否已打开指定给Redshift群集的安全组中的端口以允许来自EC2实例的连接? –

+0

@MarkB不,我该怎么做? – Rajiv

+0

您是如何打开安全组以允许从本地计算机访问的?这是相同的过程。 –

回答

0

这是不是网络或安全组

When you provision an Amazon Redshift cluster, it is locked down by default so nobody has access to it. To grant other users inbound access to an Amazon Redshift cluster, you associate the cluster with a security group.

http://docs.aws.amazon.com/redshift/latest/mgmt/working-with-security-groups.html

如果EC2是在同一个VPC,你应该确定联网红移集群。如果没有,请参阅本指南 http://docs.aws.amazon.com/redshift/latest/mgmt/enhanced-vpc-routing.html

+0

所以当我去我的EC2实例,并在描述选项卡下,我点击安全组,我看到它的VPC ID是相同的作为Redshift集群的一员,他们的两个组ID都是不同的,但是我仍然无法连接,并且它已经超时了,对不起,很新。 – Rajiv

相关问题