1

I'm stuck deploying my (second) Rails 5.2 app to AWS using Elastic Beanstalk. The code is deployed fine, but the PostgreSQL 9.4.18 database is causing problems.

EB correctly created the RDS instance. The relevant part of my database.yml is as follows:

production:
  <<: *default
  database: <%= ENV['RDS_DB_NAME'] %>
  username: <%= ENV['RDS_USERNAME'] %>
  password: <%= ENV['RDS_PASSWORD'] %>
  host: <%= ENV['RDS_HOSTNAME'] %>
  port: <%= ENV['RDS_PORT'] %>

These ENV variables are all populated in the EB web interface.

I can connect to the RDS server using pgAdmin III, having added the Inbound rule to allow my IP address access.

But here's the problem: I can't create the database after SSHing into the EC2.

When I type

rails db:seed

or

rails db:reset

I get this error:

Traceback (most recent call last):
        10: from bin/rails:4:in `<main>'
         9: from /opt/rubies/ruby-2.5.1/lib/ruby/gems/2.5.0/gems/activesupport-5.2.1/lib/active_support/dependencies.rb:287:in `require'
         8: from /opt/rubies/ruby-2.5.1/lib/ruby/gems/2.5.0/gems/activesupport-5.2.1/lib/active_support/dependencies.rb:253:in `load_dependency'
         7: from /opt/rubies/ruby-2.5.1/lib/ruby/gems/2.5.0/gems/activesupport-5.2.1/lib/active_support/dependencies.rb:287:in `block in require'
         6: from /opt/rubies/ruby-2.5.1/lib/ruby/gems/2.5.0/gems/bootsnap-1.3.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:29:in `require'
         5: from /opt/rubies/ruby-2.5.1/lib/ruby/gems/2.5.0/gems/bootsnap-1.3.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:20:in `require_with_bootsnap_lfi'
         4: from /opt/rubies/ruby-2.5.1/lib/ruby/gems/2.5.0/gems/bootsnap-1.3.1/lib/bootsnap/load_path_cache/loaded_features_index.rb:65:in `register'
         3: from /opt/rubies/ruby-2.5.1/lib/ruby/gems/2.5.0/gems/bootsnap-1.3.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in `block in require_with_bootsnap_lfi'
         2: from /opt/rubies/ruby-2.5.1/lib/ruby/gems/2.5.0/gems/bootsnap-1.3.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in `require'
         1: from /opt/rubies/ruby-2.5.1/lib/ruby/gems/2.5.0/gems/bootsnap-1.3.1/lib/bootsnap/compile_cache/iseq.rb:37:in `load_iseq'
/opt/rubies/ruby-2.5.1/lib/ruby/gems/2.5.0/gems/bootsnap-1.3.1/lib/bootsnap/compile_cache/iseq.rb:37:in `fetch': Permission denied - bs_fetch:atomic_write_cache_file:open (Errno::EACCES)

And when I try

sudo env PATH=$PATH RAILS_ENV=production bundle exec rake db:seed

I get this error

rake aborted!
PG::ConnectionBad: could not connect to server: No such file or directory
        Is the server running locally and accepting
        connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?
/opt/rubies/ruby-2.5.1/bin/bundle:23:in `load'
/opt/rubies/ruby-2.5.1/bin/bundle:23:in `<main>'
Tasks: TOP => db:abort_if_pending_migrations
(See full trace by running task with --trace)

Pretty opaque to me as I thankfully don't need to do this often.

Since my earlier app works (although on an earlier version of Ruby), I have compared RDS, Configuration and all other AWS settings I can think of. What am I missing?

MSC
  • 125
  • 7
  • Did you ever solve this? I am having the same issue – Joel Hoelting May 15 '20 at 03:52
  • @JoelHoelting - sorry was long ago but I think not. You might try step 11 from https://medium.com/@williamjoshualacey/deploy-rails-app-to-aws-2854b2338708 which I see I made a reference to in my notes around that time. I may have just ended up using pgAdmin to wipe and reseed the database (ie. manually).If you get it working, let me know! – MSC May 24 '20 at 06:22

1 Answers1

0

Had the same problem and here's what finally worked for me.

Apart from using the command provided in this answer above by benchwarmer:

https://stackoverflow.com/a/17232607/1216245

I had to run the seed command providing env vars for the master key and all rds settings.

bundle exec rake db:seed RAILS_ENV=production RAILS_MASTER_KEY=<your master key> RDS_HOSTNAME=<your rds hostname> RDS_PASSWORD=<...> RDS_USERNAME=<...> RDS_DB_NAME=<...> RDS_PORT=<...>

You can check all this in the Configuration panel for your environment in the AWS console (dashboard).

julia
  • 1