我在我的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實例連接到我的紅移集羣?謝謝!
您是否已打開指定給Redshift羣集的安全組中的端口以允許來自EC2實例的連接? –
@MarkB不,我該怎麼做? – Rajiv
您是如何打開安全組以允許從本地計算機訪問的?這是相同的過程。 –