Elastic Beanstalk不创建RDS参数

时间:2022-05-02 23:21:23

I'm following this tutorial in an effort to create a Django application on AWS.

我正在关注本教程,以便在AWS上创建Django应用程序。

http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/create_deploy_Python_django.html

http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/create_deploy_Python_django.html

I was able to get everything working with a local sqlite database but I am trying to push the app to a production server. While going through the Elastic Beanstalk init process, I choose to create an RDS instance.

我能够使用本地sqlite数据库,但我正在尝试将应用程序推送到生产服务器。在完成Elastic Beanstalk init过程的过程中,我选择创建一个RDS实例。

My mysite/settings.py looks like this:

我的mysite / settings.py看起来像这样:

import os

进口口

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': os.environ['RDS_DB_NAME'],
        'USER': os.environ['RDS_USERNAME'],
        'PASSWORD': os.environ['RDS_PASSWORD'],
        'HOST': os.environ['RDS_HOSTNAME'],
        'PORT': os.environ['RDS_PORT'],
    }
}

I should have access to RDS parameters at this point but I don't. The manage.py file becomes unresponse.

我此时应该可以访问RDS参数,但我没有。 manage.py文件变得无效。

(djangodev)laptop-id:mysite user-name$ python manage.py runserver
Unknown command: 'runserver'
Type 'manage.py help' for usage.

(djangodev)laptop-id:mysite use-name$ python manage.py
Usage: manage.py subcommand [options] [args]

Options:
  -v VERBOSITY, --verbosity=VERBOSITY
                        Verbosity level; 0=minimal output, 1=normal output,
                        2=verbose output, 3=very verbose output
  --settings=SETTINGS   The Python path to a settings module, e.g.
                        "myproject.settings.main". If this isn't provided, the
                        DJANGO_SETTINGS_MODULE environment variable will be
                        used.
  --pythonpath=PYTHONPATH
                        A directory to add to the Python path, e.g.
                        "/home/djangoprojects/myproject".
  --traceback           Print traceback on exception
  --version             show program's version number and exit
  -h, --help            show this help message and exit
Traceback (most recent call last):
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/usr/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 453, in execute_from_command_line
    utility.execute()
  File "/usr/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 376, in execute
    sys.stdout.write(self.main_help_text() + '\n')
  File "/usr/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 242, in main_help_text
    for name, app in six.iteritems(get_commands()):
  File "/usr/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 109, in get_commands
    apps = settings.INSTALLED_APPS
  File "/usr/local/lib/python2.7/site-packages/django/conf/__init__.py", line 53, in __getattr__
    self._setup(name)
  File "/usr/local/lib/python2.7/site-packages/django/conf/__init__.py", line 48, in _setup
    self._wrapped = Settings(settings_module)
  File "/usr/local/lib/python2.7/site-packages/django/conf/__init__.py", line 132, in __init__
    mod = importlib.import_module(self.SETTINGS_MODULE)
  File "/usr/local/lib/python2.7/site-packages/django/utils/importlib.py", line 35, in import_module
    __import__(name)
  File "/Users/andrewcopp/Developer/mysite/mysite/settings.py", line 17, in <module>
   'NAME': os.environ['RDS_DB_NAME'],                      # Or path to database file if using sqlite3.
  File "/tmp/djangodev/bin/../lib/python2.7/UserDict.py", line 23, in __getitem__
    raise KeyError(key)
KeyError: 'RDS_DB_NAME'

Any idea as to what I might overlooked? Anything more information I can provide to make things clear

知道我可能会忽略什么吗?我可以提供更多信息以使事情变得清晰

1 个解决方案

#1


0  

You need a local fallback to a different database in settings.

您需要在设置中本地回退到不同的数据库。

In your settings.py file, replace the DATABASE variable with this:

在settings.py文件中,将DATABASE变量替换为:

DATABASES = {}

try:
    from local_settings import *
except ImportError, e:
    DATABASES = {
        'default': {
            'ENGINE': 'django.db.backends.mysql',
            'NAME': os.environ['RDS_DB_NAME'],
            'USER': os.environ['RDS_USERNAME'],
            'PASSWORD': os.environ['
            'HOST': os.environ['RDS_HOSTNAME'],
            'PORT': os.environ['RDS_PORT'],
        }
    }

Now create a local_settings.py in the same directory as your settings.py and enter the following code:

现在在settings.py所在的目录中创建一个local_settings.py并输入以下代码:

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': 'db.djangodb',
        'USER': '',
        'PASSWORD': '',
        'HOST': '',
        'PORT': '',
    }
}

MEDIA_ROOT = ''
MEDIA_URL = ''
STATIC_ROOT = ''
STATIC_URL = '/static/'
STATICFILES_DIRS = ()
TEMPLATE_DIRS = ()

Now add your local_settings.py file to your .gitignore file.

现在将local_settings.py文件添加到.gitignore文件中。

Run $ python manage.py syncdb and now you can run the django server locally.

运行$ python manage.py syncdb,现在可以在本地运行django服务器。

Most of this is copy pasta from this blog post I found: http://grigory.ca/2012/09/getting-started-with-django-on-aws-elastic-beanstalk/

大多数这是我发现的博客文章中的复制面食:http://grigory.ca/2012/09/getting-started-with-django-on-aws-elastic-beanstalk/

#1


0  

You need a local fallback to a different database in settings.

您需要在设置中本地回退到不同的数据库。

In your settings.py file, replace the DATABASE variable with this:

在settings.py文件中,将DATABASE变量替换为:

DATABASES = {}

try:
    from local_settings import *
except ImportError, e:
    DATABASES = {
        'default': {
            'ENGINE': 'django.db.backends.mysql',
            'NAME': os.environ['RDS_DB_NAME'],
            'USER': os.environ['RDS_USERNAME'],
            'PASSWORD': os.environ['
            'HOST': os.environ['RDS_HOSTNAME'],
            'PORT': os.environ['RDS_PORT'],
        }
    }

Now create a local_settings.py in the same directory as your settings.py and enter the following code:

现在在settings.py所在的目录中创建一个local_settings.py并输入以下代码:

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': 'db.djangodb',
        'USER': '',
        'PASSWORD': '',
        'HOST': '',
        'PORT': '',
    }
}

MEDIA_ROOT = ''
MEDIA_URL = ''
STATIC_ROOT = ''
STATIC_URL = '/static/'
STATICFILES_DIRS = ()
TEMPLATE_DIRS = ()

Now add your local_settings.py file to your .gitignore file.

现在将local_settings.py文件添加到.gitignore文件中。

Run $ python manage.py syncdb and now you can run the django server locally.

运行$ python manage.py syncdb,现在可以在本地运行django服务器。

Most of this is copy pasta from this blog post I found: http://grigory.ca/2012/09/getting-started-with-django-on-aws-elastic-beanstalk/

大多数这是我发现的博客文章中的复制面食:http://grigory.ca/2012/09/getting-started-with-django-on-aws-elastic-beanstalk/