简体   繁体   English

Amazon RDS 上的 PostgresSQL

[英]PostgresSQL on Amazon RDS

I have configured a PostgresSQL database instance on Amazon RDS and want to use it from the python script.我已经在 Amazon RDS 上配置了一个 PostgresSQL 数据库实例,并想从 python 脚本中使用它。 I am using awswrangler for it.我正在使用 awswrangler。

Below is the python script.下面是python脚本。

import awswrangler as wr

df1 = pd.DataFrame({
    "id": [1, 2],
    "name": ["foo", "boo"]
})

eng_postgresql = wr.db.get_engine(db_type="postgresql", host=ENDPOINT, port=5432, database=DBNAME, user=USR, password=pass)

wr.db.to_sql(df1, eng_postgresql, schema="public", name="tutorial", if_exists="replace", index=False)  # PostgreSQL

I am getting the below error:我收到以下错误:

sqlalchemy.exc.OperationalError: (psycopg2.OperationalError) could not connect to server: Operation timed out
    Is the server running on host "*************.rds.amazonaws.com" (172.31.23.226) and accepting
    TCP/IP connections on port 5432?

Based on the comments.根据评论。

The connection time outs due to the fact that the RDS is not public .由于 RDS不是公开的,连接超时。 Subsequently, connections over the internet will fail.随后,通过 Internet 的连接将失败。

There are generally three solutions to this problem;这个问题一般有三种解决方案;

  1. Modify the RDS instance to have public ip. 修改RDS实例有公网ip。 For this the RDS must be in public subnet with security groups allowing connections from outside of AWS.为此,RDS 必须位于具有允许来自 AWS 外部的连接的安全组的公共子网中。
  2. Setup a bastion host and use ssh tunnel , to tunnel connections over the internet to the private DB instance.设置堡垒主机并使用ssh 隧道,通过互联网将连接隧道连接到私有数据库实例。
  3. Setup a VPN connection between home/work and the VPC where the RDS instance is.在家庭/工作和RDS实例所在的VPC之间建立VPN连接

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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