简体   繁体   English

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

[英]how to connect Django in EC2 to a Postgres database in RDS?

First time using AWS services with Django. 首次在Django上使用AWS服务。

Was wondering how to configure the Django app running in a EC2 instance to a Postgres database in RDS? 想知道如何将在EC2实例中运行的Django应用程序配置为RDS中的Postgres数据库?

the EC2 is running ubuntu 14.04 EC2正在运行ubuntu 14.04

Any special configuration required? 需要什么特殊配置?

All you need to do, before doing the normal migration documented in the official tutorial be sure to have your RDS instance available and accessible to your EC2 instance . 在完成官方教程中记录的正常迁移之前,您需要做的就是确保您的RDS实例可用并可供EC2实例访问

Then what you need to do, is to modify the settings.py file of your app in the DATABSES section in the following way 那么你需要做的是,通过以下方式修改DATABSES部分中应用程序的settings.py文件

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',
    }
}

Following this, continue to migrate normally and all should work well. 在此之后,继续正常迁移,一切都应该运行良好。

If you are able to use a deployment service, take a look at at AWS Elastic Beanstalk . 如果您能够使用部署服务,请查看AWS Elastic Beanstalk It combines EC2, RDS and S3 storage into a Docker and helps keep them together. 它将EC2,RDS和S3存储结合到Docker中,并帮助将它们保持在一起。 It's really easy to connect your RDS instance to your EC2 instance(s). 将RDS实例连接到EC2实例非常容易。 I just launched a Django project using that a few weeks ago. 几周前我刚刚使用它启动了一个Django项目。

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

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