我需要将 Heroku 应用程序指向我的 AWS RDS 数据库.我的 RDS 数据库已启动并正在运行,并且有一个具有 0.0.0.0/0 访问权限的安全组.
I need to point my Heroku application to my AWS RDS database. My RDS database is up and running and has a security group with 0.0.0.0/0 access.
目前,我已经删除了我的 Heroku postgreSQL 数据库,并且我正在尝试将我的 Heroku 应用程序指向我的 RDS 数据库.由于某种原因,我的应用程序崩溃了.我相信我正在进行的步骤是在 Heroku 端设置我的 DATABASE_URL.
Currently, I've removed my Heroku postgreSQL database and I am attempting to point my Heroku application to my RDS database. For some reason my application is crashing. The step that I believe I am on is setting my DATABASE_URL on the Heroku side.
假设我的数据库凭据是:
Let's say that my database credentials are:
数据库实例:mydb 数据库名称:mydb 用户: wcronyn pass:密码
db instance: mydb dbname: mydb user: wcronyn pass: password
我试过了:
heroku config:set DATABASE_URL=postgres://wcronyn:password@mydb.XXXXXXX.us-east-1.rds.amazonaws:5432/mydb
heroku config:set DATABASE_URL=postgres://wcronyn:password@mydb.XXXXXXX.us-east-1.rds.amazonaws:5432/mydb
并且我尝试通过将 .pem 文件下载到我的配置文件夹中然后引用它来设置权限:
and I've attempted to set the permissions by downloading the .pem file into my config folder and then referencing it:
DATABASE_URL=postgres://wcronyn:password@mydb.XXXXXXX.us-east-1.rds.amazonaws:5432/mydb?sslca=config/amazon-rds-ca-cert.pem&sslmode=require&加密=真
DATABASE_URL=postgres://wcronyn:password@mydb.XXXXXXX.us-east-1.rds.amazonaws:5432/mydb?sslca=config/amazon-rds-ca-cert.pem&sslmode=require&encrypt=true
我已经尝试过这两个数据库网址,但我的应用程序一直崩溃.
I have tried these two database urls but my application keeps crashing.
有人可以概述成功托管我的 RDS 数据库并将我的应用程序指向它需要采取的步骤吗?
Can someone outline the steps that I need to take to successfully host my RDS database and point my application to it?
推荐答案鉴于以下设置,以下步骤对我有用(2017 年 2 月):
The following steps worked for me (Feb 2017), given the following setup:
- AWS RDS 区域 eu-west-2(使用 VPC 安全组,而不是 DB安全组)
- Postgres 9.6
- Heroku,托管 Flask 应用程序(例如 appname:heroku-app-stage)
- 将远程添加到 Heroku 应用程序的 Git(例如远程:stage)
- postgresql://username:password@awsrdshost:5432/dbname 的 DATABASE_URL 值
- AWS RDS Region eu-west-2 (which uses VPC Security Groups, not DB Security Groups)
- Postgres 9.6
- Heroku, hosting a Flask application (eg appname: heroku-app-stage)
- Git with a remote added into the Heroku app (eg remote: stage)
- DATABASE_URL value of postgresql://username:password@awsrdshost:5432/dbname
大致有四个步骤:
下载并安装 Amazon RDS SSL 根证书
配置 Heroku 以引用根证书
请注意,此答案使用根证书;可能还有其他选项可能是您想要的,在这种情况下,请参考以下 SO:
Note that this answer uses a root certificate; there may be other options which may be what you want in which case refer to the following SO:
如何连接到远程 PostgreSQL 数据库蟒蛇
在您的 RDS 实例上启用 SSL
配置 RDS 安全组以允许所有传入 IP 范围
注意:仅当您使用使用 VPC 安全组的 RDS 设置时,说明才相关
Note: instructions are only relevant if you're using an RDS setup that uses VPC Security Groups
就是这样!
所用参考页面的链接:
Amazon 的 Postgres SSL 指南docs.aws.amazon/AmazonRDS/latest/UserGuide/CHAP_PostgreSQL.html#PostgreSQL.Concepts.General.SSL
Amazon's guide to SSL on Postgres docs.aws.amazon/AmazonRDS/latest/UserGuide/CHAP_PostgreSQL.html#PostgreSQL.Concepts.General.SSL
Heroku 的(非常简短的)Amazon RDS 指南devcenter.heroku/articles/amazon-rds
Heroku's (very short) guide to Amazon RDS devcenter.heroku/articles/amazon-rds
更多推荐
将 Heroku 应用程序指向 AWS RDS 数据库
发布评论