如何将EC2中的Django连接到RDS中的Postgres数据库?

Kim*_*cks 7 django amazon-ec2 amazon-web-services amazon-rds

首次在Django上使用AWS服务.

想知道如何将在EC2实例中运行的Django应用程序配置为RDS中的Postgres数据库?

EC2正在运行ubuntu 14.04

需要什么特殊配置?

blu*_*ers 12

在完成官方教程中记录的正常迁移之前,您需要做的就是确保您的RDS实例可用并可供EC2实例访问.

然后,您需要做的是按以下方式修改部分中的settings.py应用程序文件DATABSES

DATABASES = {
'default': {
    'ENGINE': 'django.db.backends.postgresql',
    'NAME': '<name defined upon RDS creation>',
    'USER': '<username defined upon RDS creation>',
    'PASSWORD': '<password defined upon RDS creation>',
    'HOST': '<this can be found in "Endpoint" on your RDS dashboard, exclude the ":" and the port number>',
    'PORT': '5432',
    }
}
Run Code Online (Sandbox Code Playgroud)

在此之后,继续正常迁移,一切都应该运行良好.