部署rails应用程序到Elastic beanstalk无法连接到RDS

时间:2014-02-09 16:29:31

标签: ruby-on-rails ruby amazon-web-services elastic-beanstalk

我正在尝试按照this tutorial将我的应用部署到Elastic Beanstalk。

如果我使用splite3,该应用可行,但我无法将该应用连接到RDS。

我在Gemfile中添加了group :production do gem 'mysql2' end,并将此代码添加到config/database.yml

production:
  adapter: mysql2
  encoding: utf8
  database: <%= ENV['RDS_DB_NAME'] %>
  username: <%= ENV['RDS_USERNAME'] %>
  password: <%= ENV['RDS_PASSWORD'] %>
  host: <%= ENV['RDS_HOSTNAME'] %>
  port: <%= ENV['RDS_PORT'] %>

我在Elastic Beanstalk console中添加了RDS。

production.log显示错误,表示数据库连接失败。

-------------------------------------
/var/app/support/logs/production.log
-------------------------------------
I, [2014-02-09T16:01:56.520967 #29379]  INFO -- : Started GET "/" for xxx.xxx.xxx.xxx at 2014-02-09 16:01:56 +0000
I, [2014-02-09T16:01:56.620738 #29379]  INFO -- : Processing by PostsController#index as HTML
E, [2014-02-09T16:01:56.629835 #29379] ERROR -- : Mysql2::Error: Table 'ebdb.posts' doesn't exist: SELECT `posts`.* FROM `posts`
I, [2014-02-09T16:01:56.630802 #29379]  INFO -- :   Rendered posts/index.html.erb within layouts/application (4.3ms)
I, [2014-02-09T16:01:56.631068 #29379]  INFO -- : Completed 500 Internal Server Error in 10ms
F, [2014-02-09T16:01:56.633962 #29379] FATAL -- : 
ActionView::Template::Error (Mysql2::Error: Table 'ebdb.posts' doesn't exist: SELECT `posts`.* FROM `posts`):

eb status就是这样。

URL     : myAppURL
Status      : Ready
Health      : Green

RDS Database: AWSEBRDSDatabase | myDatabaseURL:port

可能我会错过一些非常基本的东西。我该怎么做才能解决这个问题?

1 个答案:

答案 0 :(得分:1)

如果您的数据库未命名为ebdb,您可以在YAML文件中对您的数据库名称进行硬编码:

production:
  adapter: mysql2
  encoding: utf8
  database: my_database_name
  username: <%= ENV['RDS_USERNAME'] %>
  password: <%= ENV['RDS_PASSWORD'] %>
  host: <%= ENV['RDS_HOSTNAME'] %>
  port: <%= ENV['RDS_PORT'] %>