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

相關問題