I am migrating a Ruby on Rails app from Heroku free tier to Amazon Elastic Beanstalk. I've successfully pg_dump ed the Heroku database and pg_restore d into Amazon RDS. The RDS_HOST, RDS_PORT environment variables are set. When I try to deploy the app, I get the mysterious PG::ConnectionBad: FATAL: role "webapp" does not exist error. I even go as far as create role webapp in psql to no avail. webapp is not in the database config file. I'm lost. Any help would be appreciated.
----------------------------------------
/var/log/eb-engine.log
----------------------------------------
/opt/elasticbeanstalk/.rbenv/versions/2.7.6/bin/bundle:25:in `load'
/opt/elasticbeanstalk/.rbenv/versions/2.7.6/bin/bundle:25:in `<main>'
Caused by:
PG::ConnectionBad: FATAL: role "webapp" does not exist
/var/app/staging/vendor/bundle/ruby/2.7.0/gems/pg-1.2.3/lib/pg.rb:58:in `initialize'
/var/app/staging/vendor/bundle/ruby/2.7.0/gems/pg-1.2.3/lib/pg.rb:58:in `new'
/var/app/staging/vendor/bundle/ruby/2.7.0/gems/pg-1.2.3/lib/pg.rb:58:in `connect'
/var/app/staging/vendor/bundle/ruby/2.7.0/gems/activerecord-6.0.3.6/lib/active_record/connection_adapters/postgresql_adapter.rb:46:in `postgresql_connection'
/var/app/staging/vendor/bundle/ruby/2.7.0/gems/activerecord-6.0.3.6/lib/active_record/connection_adapters/abstract/connection_pool.rb:887:in `new_connection'
/var/app/staging/vendor/bundle/ruby/2.7.0/gems/activerecord-6.0.3.6/lib/active_record/connection_adapters/abstract/connection_pool.rb:931:in `checkout_new_connection'
/var/app/staging/vendor/bundle/ruby/2.7.0/gems/activerecord-6.0.3.6/lib/active_record/connection_adapters/abstract/connection_pool.rb:910:in `try_to_checkout_new_connection'
/var/app/staging/vendor/bundle/ruby/2.7.0/gems/activerecord-6.0.3.6/lib/active_record/connection_adapters/abstract/connection_pool.rb:871:in `acquire_connection'
/var/app/staging/vendor/bundle/ruby/2.7.0/gems/activerecord-6.0.3.6/lib/active_record/connection_adapters/abstract/connection_pool.rb:593:in `checkout'
/var/app/staging/vendor/bundle/ruby/2.7.0/gems/activerecord-6.0.3.6/lib/active_record/connection_adapters/abstract/connection_pool.rb:437:in `connection'
/var/app/staging/vendor/bundle/ruby/2.7.0/gems/activerecord-6.0.3.6/lib/active_record/connection_adapters/abstract/connection_pool.rb:1119:in `retrieve_connection'
/var/app/staging/vendor/bundle/ruby/2.7.0/gems/activerecord-6.0.3.6/lib/active_record/connection_handling.rb:221:in `retrieve_connection'
/var/app/staging/vendor/bundle/ruby/2.7.0/gems/activerecord-6.0.3.6/lib/active_record/connection_handling.rb:189:in `connection'
/var/app/staging/vendor/bundle/ruby/2.7.0/gems/activerecord-6.0.3.6/lib/active_record/tasks/database_tasks.rb:238:in `migrate'
/var/app/staging/vendor/bundle/ruby/2.7.0/gems/activerecord-6.0.3.6/lib/active_record/railties/databases.rake:86:in `block (3 levels) in <main>'
/var/app/staging/vendor/bundle/ruby/2.7.0/gems/activerecord-6.0.3.6/lib/active_record/railties/databases.rake:84:in `each'
/var/app/staging/vendor/bundle/ruby/2.7.0/gems/activerecord-6.0.3.6/lib/active_record/railties/databases.rake:84:in `block (2 levels) in <main>'
/var/app/staging/vendor/bundle/ruby/2.7.0/gems/rake-13.0.3/exe/rake:27:in `<top (required)>'
/opt/elasticbeanstalk/.rbenv/versions/2.7.6/bin/bundle:25:in `load'
/opt/elasticbeanstalk/.rbenv/versions/2.7.6/bin/bundle:25:in `<main>'
Tasks: TOP => db:migrate
(See full trace by running task with --trace)
2022/11/22 20:25:26.849822 [ERROR] An error occurred during execution of command [app-deploy] - [rake tasks]. Stop running the command. Error: running rake task db:migrate failed with error command bundle exec rake db:migrate failed with error Command /bin/su webapp -c bundle exec rake db:migrate failed with error exit status 1. Stderr:/var/app/staging/vendor/bundle/ruby/2.7.0/gems/bootstrap-4.6.0/lib/bootstrap/version.rb:4: warning: already initialized constant Bootstrap::VERSION
/var/app/staging/vendor/bundle/ruby/2.7.0/gems/bootstrap-sass-3.4.1/lib/bootstrap-sass/version.rb:2: warning: previous definition of VERSION was here
/var/app/staging/vendor/bundle/ruby/2.7.0/gems/bootstrap-4.6.0/lib/bootstrap/version.rb:5: warning: already initialized constant Bootstrap::BOOTSTRAP_SHA
/var/app/staging/vendor/bundle/ruby/2.7.0/gems/bootstrap-sass-3.4.1/lib/bootstrap-sass/version.rb:3: warning: previous definition of BOOTSTRAP_SHA was here
rake aborted!
TypeError: no implicit conversion of nil into String
/var/app/staging/vendor/bundle/ruby/2.7.0/gems/activerecord-6.0.3.6/lib/active_record/connection_adapters/postgresql_adapter.rb:49:in `include?'
/var/app/staging/vendor/bundle/ruby/2.7.0/gems/activerecord-6.0.3.6/lib/active_record/connection_adapters/postgresql_adapter.rb:49:in `rescue in postgresql_connection'
/var/app/staging/vendor/bundle/ruby/2.7.0/gems/activerecord-6.0.3.6/lib/active_record/connection_adapters/postgresql_adapter.rb:33:in `postgresql_connection'
/var/app/staging/vendor/bundle/ruby/2.7.0/gems/activerecord-6.0.3.6/lib/active_record/connection_adapters/abstract/connection_pool.rb:887:in `new_connection'
/var/app/staging/vendor/bundle/ruby/2.7.0/gems/activerecord-6.0.3.6/lib/active_record/connection_adapters/abstract/connection_pool.rb:931:in `checkout_new_connection'
/var/app/staging/vendor/bundle/ruby/2.7.0/gems/activerecord-6.0.3.6/lib/active_record/connection_adapters/abstract/connection_pool.rb:910:in `try_to_checkout_new_connection'
/var/app/staging/vendor/bundle/ruby/2.7.0/gems/activerecord-6.0.3.6/lib/active_record/connection_adapters/abstract/connection_pool.rb:871:in `acquire_connection'
/var/app/staging/vendor/bundle/ruby/2.7.0/gems/activerecord-6.0.3.6/lib/active_record/connection_adapters/abstract/connection_pool.rb:593:in `checkout'
/var/app/staging/vendor/bundle/ruby/2.7.0/gems/activerecord-6.0.3.6/lib/active_record/connection_adapters/abstract/connection_pool.rb:437:in `connection'
/var/app/staging/vendor/bundle/ruby/2.7.0/gems/activerecord-6.0.3.6/lib/active_record/connection_adapters/abstract/connection_pool.rb:1119:in `retrieve_connection'
/var/app/staging/vendor/bundle/ruby/2.7.0/gems/activerecord-6.0.3.6/lib/active_record/connection_handling.rb:221:in `retrieve_connection'
/var/app/staging/vendor/bundle/ruby/2.7.0/gems/activerecord-6.0.3.6/lib/active_record/connection_handling.rb:189:in `connection'
/var/app/staging/vendor/bundle/ruby/2.7.0/gems/activerecord-6.0.3.6/lib/active_record/tasks/database_tasks.rb:238:in `migrate'
/var/app/staging/vendor/bundle/ruby/2.7.0/gems/activerecord-6.0.3.6/lib/active_record/railties/databases.rake:86:in `block (3 levels) in <main>'
/var/app/staging/vendor/bundle/ruby/2.7.0/gems/activerecord-6.0.3.6/lib/active_record/railties/databases.rake:84:in `each'
/var/app/staging/vendor/bundle/ruby/2.7.0/gems/activerecord-6.0.3.6/lib/active_record/railties/databases.rake:84:in `block (2 levels) in <main>'
/var/app/staging/vendor/bundle/ruby/2.7.0/gems/rake-13.0.3/exe/rake:27:in `<top (required)>'
/opt/elasticbeanstalk/.rbenv/versions/2.7.6/bin/bundle:25:in `load'
/opt/elasticbeanstalk/.rbenv/versions/2.7.6/bin/bundle:25:in `<main>'
Caused by:
PG::ConnectionBad: FATAL: role "webapp" does not exist
/var/app/staging/vendor/bundle/ruby/2.7.0/gems/pg-1.2.3/lib/pg.rb:58:in `initialize'
/var/app/staging/vendor/bundle/ruby/2.7.0/gems/pg-1.2.3/lib/pg.rb:58:in `new'
/var/app/staging/vendor/bundle/ruby/2.7.0/gems/pg-1.2.3/lib/pg.rb:58:in `connect'
/var/app/staging/vendor/bundle/ruby/2.7.0/gems/activerecord-6.0.3.6/lib/active_record/connection_adapters/postgresql_adapter.rb:46:in `postgresql_connection'
/var/app/staging/vendor/bundle/ruby/2.7.0/gems/activerecord-6.0.3.6/lib/active_record/connection_adapters/abstract/connection_pool.rb:887:in `new_connection'
/var/app/staging/vendor/bundle/ruby/2.7.0/gems/activerecord-6.0.3.6/lib/active_record/connection_adapters/abstract/connection_pool.rb:931:in `checkout_new_connection'
/var/app/staging/vendor/bundle/ruby/2.7.0/gems/activerecord-6.0.3.6/lib/active_record/connection_adapters/abstract/connection_pool.rb:910:in `try_to_checkout_new_connection'
/var/app/staging/vendor/bundle/ruby/2.7.0/gems/activerecord-6.0.3.6/lib/active_record/connection_adapters/abstract/connection_pool.rb:871:in `acquire_connection'
/var/app/staging/vendor/bundle/ruby/2.7.0/gems/activerecord-6.0.3.6/lib/active_record/connection_adapters/abstract/connection_pool.rb:593:in `checkout'
/var/app/staging/vendor/bundle/ruby/2.7.0/gems/activerecord-6.0.3.6/lib/active_record/connection_adapters/abstract/connection_pool.rb:437:in `connection'
/var/app/staging/vendor/bundle/ruby/2.7.0/gems/activerecord-6.0.3.6/lib/active_record/connection_adapters/abstract/connection_pool.rb:1119:in `retrieve_connection'
/var/app/staging/vendor/bundle/ruby/2.7.0/gems/activerecord-6.0.3.6/lib/active_record/connection_handling.rb:221:in `retrieve_connection'
/var/app/staging/vendor/bundle/ruby/2.7.0/gems/activerecord-6.0.3.6/lib/active_record/connection_handling.rb:189:in `connection'
/var/app/staging/vendor/bundle/ruby/2.7.0/gems/activerecord-6.0.3.6/lib/active_record/tasks/database_tasks.rb:238:in `migrate'
/var/app/staging/vendor/bundle/ruby/2.7.0/gems/activerecord-6.0.3.6/lib/active_record/railties/databases.rake:86:in `block (3 levels) in <main>'
/var/app/staging/vendor/bundle/ruby/2.7.0/gems/activerecord-6.0.3.6/lib/active_record/railties/databases.rake:84:in `each'
/var/app/staging/vendor/bundle/ruby/2.7.0/gems/activerecord-6.0.3.6/lib/active_record/railties/databases.rake:84:in `block (2 levels) in <main>'
/var/app/staging/vendor/bundle/ruby/2.7.0/gems/rake-13.0.3/exe/rake:27:in `<top (required)>'
/opt/elasticbeanstalk/.rbenv/versions/2.7.6/bin/bundle:25:in `load'
/opt/elasticbeanstalk/.rbenv/versions/2.7.6/bin/bundle:25:in `<main>'
Tasks: TOP => db:migrate
(See full trace by running task with --trace)
2022/11/22 20:25:26.849831 [INFO] Executing cleanup logic
2022/11/22 20:25:26.849925 [INFO] CommandService Response: {"status":"FAILURE","api_version":"1.0","results":[{"status":"FAILURE","msg":"Engine execution has encountered an error.","returncode":1,"events":[{"msg":"Instance deployment failed. For details, see 'eb-engine.log'.","timestamp":1669148726849,"severity":"ERROR"}]}]}
2022/11/22 20:25:26.850115 [INFO] Platform Engine finished execution on command: app-deploy
2022/11/22 21:03:55.125043 [INFO] Starting...
2022/11/22 21:03:55.125093 [INFO] Starting EBPlatform-PlatformEngine
2022/11/22 21:03:55.125113 [INFO] reading event message file
2022/11/22 21:03:55.125253 [INFO] Engine received EB command cfn-hup-exec
2022/11/22 21:03:55.336348 [INFO] Running command /bin/sh -c /opt/aws/bin/cfn-get-metadata -s arn:aws:cloudformation:us-east-1:430857556399:stack/awseb-e-it23dtcamf-stack/b30b9b70-693c-11ed-9147-0ec07ab1c2b3 -r AWSEBAutoScalingGroup --region us-east-1
2022/11/22 21:03:56.787676 [INFO] Running command /bin/sh -c /opt/aws/bin/cfn-get-metadata -s arn:aws:cloudformation:us-east-1:430857556399:stack/awseb-e-it23dtcamf-stack/b30b9b70-693c-11ed-9147-0ec07ab1c2b3 -r AWSEBBeanstalkMetadata --region us-east-1
2022/11/22 21:03:58.178531 [INFO] checking whether command tail-log is applicable to this instance...
2022/11/22 21:03:58.178547 [INFO] this command is applicable to the instance, thus instance should execute command
2022/11/22 21:03:58.178551 [INFO] Engine command: (tail-log)
2022/11/22 21:03:58.178604 [INFO] Executing instruction: GetTailLogs
2022/11/22 21:03:58.178609 [INFO] Tail Logs...
2022/11/22 21:03:58.178840 [INFO] Running command /bin/sh -c tail -n 100 /var/log/web.stdout.log
2022/11/22 21:03:58.197220 [INFO] Running command /bin/sh -c tail -n 100 /var/log/eb-engine.log
Here is the config/database.yml:
default: &default
adapter: postgresql
encoding: unicode
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
development:
<<: *default
database: receipts_development
test:
<<: *default
database: receipts_test
production:
<<: *default
adapter: postgresql
encoding: utf8
database: <%= ENV['RDS_DB_NAME'] %>
username: <%= ENV['RDS_USERNAME'] %>
password: <%= ENV['RDS_PASSWORD'] %>
host: <%= ENV['RDS_HOSTNAME'] %>
port: <%= ENV['RDS_PORT'] %>
Here is the Gemfile:
source 'https://rubygems.org'
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
ruby '2.7.6'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '~> 6.0.3', '>= 6.0.3.6'
# Use postgresql as the database for Active Record
gem 'pg', '>= 0.18', '< 2.0'
# Use Puma as the app server
gem 'puma', '~> 4.1'
# Use SCSS for stylesheets
gem 'sass-rails', '>= 6'
# Transpile app-like JavaScript. Read more: https://github.com/rails/webpacker
gem 'webpacker', '~> 4.0'
# Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks
gem 'turbolinks', '~> 5'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.7'
# Use Redis adapter to run Action Cable in production
# gem 'redis', '~> 4.0'
# Use Active Model has_secure_password
# gem 'bcrypt', '~> 3.1.7'
# Use Active Storage variant
# gem 'image_processing', '~> 1.2'
# Reduces boot times through caching; required in config/boot.rb
gem 'bootsnap', '>= 1.4.2', require: false
gem 'bootstrap-sass'
gem 'bootstrap'
gem 'carrierwave-aws'
gem 'carrierwave', '~> 2.0'
gem 'mini_magick'
gem 'aws-sdk-rails'
#gem 'figaro'
gem 'aws-sdk'
gem 'jquery-fileupload-rails'
# Use ActiveModel has_secure_password
gem 'bcrypt', '~> 3.1.7'
# need sengrid-ruby for emails
gem "sendgrid-ruby"
gem 'rack-cors' #javascript preflight
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]