python - 无法连接到我的 AWS 数据库实例 | psql : could not connect to server: Operation timed out

标签 python django database postgresql amazon-web-services

我在 AWS RDS 上创建了一个 postgres 数据库实例。我正在尝试将此数据库实例连接到我的 django zappa 应用程序,以便我可以执行 AWS Lambda 函数。

我已经向我的数据库实例添加了一个新的安全组,这样我就可以允许我的 Django 应用程序连接到它:

enter image description here

我的数据库详细信息显示新安全组处于事件状态:

enter image description here

然而,当我尝试连接到它时,要么通过运行 psql --host="*************.us-east-2.rds.amazonaws.com"--port="5432"--username="*********"--password --dbname="*****" 通过我的终端,

或者通过我的 pgadmin 界面,它返回这个错误:

psql: could not connect to server: Operation timed out
    Is the server running on host "***********.us-east-2.rds.amazonaws.com" (18.191.94.44) and accepting
    TCP/IP connections on port 5432?

知道它为什么这样做吗?

最佳答案

最常见的错误是没有允许自己访问/没有设置为公共(public)可访问性。

  1. 确保 RDS 数据库实例被标记为 publicly accessible (改为是。

Select Yes if you want EC2 instances and devices outside of the VPC hosting the DB instance to connect to the DB instance. If you select No, Amazon RDS will not assign a public IP address to the DB instance, and no EC2 instance or devices outside of the VPC will be able to connect. If you select Yes, you must also select one or more VPC security groups that specify which EC2 instances and devices can connect to the DB instance.

  1. 确保您已允许自己访问 Security Group RDS 数据库。您应该添加或更改当前的入站规则以允许您的 ip(或 0.0.0.0/0 作为最后的手段 - 互联网上的任何人都可以连接)访问您端口上的 RDS。默认情况下,出站规则已设置为 0.0.0.0/0

关于python - 无法连接到我的 AWS 数据库实例 | psql : could not connect to server: Operation timed out,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50984887/

相关文章:

java - 我们应该在 Java Eclipse Dynamic Web 项目中的哪里存储数据库配置文件?

python - 如何指定一个属性必须是一个(比方说)整数列表,而不仅仅是一个列表?

python - 无法导入 python 模块

python - sklearn - 如何获得概率而不是标签?

django - 创建实例时如何更新 ManyToManyField

Django-CMS - 全局占位符?

php - 使用外键在表中添加数据

sql - 将数组存储为字段值或将数组值存储为记录是个好主意吗?

python - Pandas Dataframe Parquet 数据类型?

django - 使用自定义用户管理打破 Django 管理中的更改密码表单