Assuming you are ssh'd into the instance.
$ cd /srv/www/yourapplication/current
$ sudo bundle exec rails console
Question
I am trying to run a rails console in amazon opsworks, I have tried:
sudo rails console -e production
sudo rails console production
RAILS_ENV=production sudo rails console
RAILS_ENV=production RACK_ENV=production sudo rails console
With each of those commands the console is spinning up in the development environment. What do I need to do to get this console started in the environment of my choosing?
La solution 2
Assuming you are ssh'd into the instance.
$ cd /srv/www/yourapplication/current
$ sudo bundle exec rails console
Autres conseils
sudo su deploy # switch to the app user
cd /srv/www/myapp/current # your deploy dir might be different (check logs if unsure)
RAILS_ENV=production bundle exec rails console
Solution 1 (faster): You can add environment variables from .env(.environment)-file with this gem https://github.com/bkeepers/dotenv. You have to write down all keys and values in this file which you need to load.
Solution 2 (better): Do it like described here: http://dev.mikamai.com/post/90567083464/use-the-env-luke-aka-simulate-the-env-in
If you'd prefer to load environment variables without running it as root and without adding dotenv to your Gemfile:
$ cd /srv/www/<NAME_OF_YOUR_APP>/current
$ sudo -u deploy -E bundle exec rails console production