I have been trying to access my production console on my ec2 instance as part of my elastic beanstalk environment. I am able to actually access the console, but when I query for an object, eg. "Wager.all", it gives me this error:
[root@ip-10-0-1-146 config]# bundle exec rails c -e production Loading production environment (Rails 5.2.4.2) irb(main):001:0> Wager.all Traceback (most recent call last): PG::ConnectionBad (fe_sendauth: no password supplied)
Here is my database.yml file (production configuration is the one to look at):
default: &default
adapter: postgresql
encoding: UTF-8
host: 'localhost'
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 10 } %>
test:
<<: *default
development:
<<: *default
url: <%= ENV['DATABASE_URL'] %>
database: <%= ENV['RDS_DB_NAME'] %>
username: <%= ENV['RDS_USERNAME'] %>
password: <%= ENV['RDS_PASSWORD'] %>
host: <%= ENV['RDS_HOSTNAME'] %>
port: <%= ENV['RDS_PORT'] %>
production:
<<: *default
url: <%= ENV['DATABASE_URL'] %>
database: <%= ENV['RDS_DB_NAME'] %>
username: <%= ENV['RDS_USERNAME'] %>
password: <%= ENV['RDS_PASSWORD'] %>
host: database-1.c76xg56p4vkw.us-east-2.rds.amazonaws.com
port: 5432
Before, I had the host and port option set to environment variables and it failed on that because it couldn't even connect to the host. Now that I have hardcoded that in, it fails on the part where it requires my password. I can get this to work by hardcoding everything, but I want to use env variables.
Even though I have set my environment variables in my elastic beanstalk console, it seems like the rails console is unable to retrieve them. However, it does appear that the application is accessing these variables during deployment, since it can connect to my database.
Things I've tried:
Running 'erb config/database.yml' to see if erb can recognize the values. It returns blank values for all the fields where I have something specified in <%= %>. So 'password: <%= ENV['RDS_PASSWORD']' %> would be output like 'password: '.
I've referred to this AWS doc to set up my database.yml file
Called AWS customer support, and we confirmed that the instance does seem to know about environment variables. This command '/opt/elasticbeanstalk/bin/get-config environment' outputs all the env variables correctly. However, the support associate did not know much about rails so he was unable to help me further.
ruby 2.5.8p224 (2020-03-31 revision 67882) [x86_64-linux]