1

Recently I hosted my Ruby on Rails application on Amazon EC2 using Elastic Beanstalk. Everything works fine except my seeds.rb file. My seeds.rb file is not executed at the time of hosting. I am using ActiveAdmin also and I define first admin on my seeds.rb file.

How can I create first admin user on Amazon by rails console? Is there any way to open Rails Console on Amazon EC2 ? I am trying to do this using putty but don't know how to do this. Please give me some pointers..

Free-Minded
  • 5,322
  • 6
  • 50
  • 93

3 Answers3

8

Are you not supposed to do something like this?

# .ebextensions/bundles_container.config
container_commands:
  01-bundle-install:
    command: "bundle install"
    leader_only: true
  02-bundle-db-migrate:
    command: "bundle exec rake db:migrate"
    leader_only: true
  03-bundle-db-seed:
    command: "bundle exec rake db:seed RAILS_ENV='staging'"
    leader_only: true

You can also pass parameters if needed, or combine all those commands with "cmd1 && cmd2".

Ker Ruben Ramos
  • 642
  • 5
  • 13
3

You need to create keypair to access the amazon instance(which i think you already have). Make sure that ssh access is enabled in the current selected security group.

You can connect to the amazon instance using

ssh -i path/to/keypair.pub ec2-user@ec2-an-ip-address.compute-1.amazonaws.com

Then cd into the app directory and run bundle exec rake db:seed RAILS_ENV='staging' assuming that you're running the app in staging environment.

benchwarmer
  • 2,764
  • 23
  • 25
1

In case you're here and the above solutions didn't work for you.

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=<...>

And it worked, finally :)

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

Julia Jacobs
  • 469
  • 4
  • 7