I am trying to bring up a staging instance of rails applciation using elastic beanstalk. I followed the documentation and did the following :
eb init --environment staging
eb start --environment staging
After this, I checked that the .elasticbeanstalk/optionsettings still had 'production' as the environment. I manually updated this to staging, and tried the git aws.push command.
After sometime, everything was deployed, However, when I load the URL, the application still seems to be using all the production configs and not the staging. Am I missing any step ?
The --environment
switch in the eb
CLI tool does not refer to the Rails environment, it refers to the Elastic Beanstalk environment which you are attempting to launch. The Elastic Beanstalk environment is a set of provisioned resources for a deployed application version. This is different from a Rails/Rack environment, which is simply a user defined context for application code to run in on an individual machine.
In order to set your Rails environment, you will want to set the RACK_ENV
(or RAILS_ENV
) environment variable inside of your .elasticbeanstalk/optionsettings
file after an eb start
and then call eb update
to trigger an update of these environment variables. Or, you can edit your Elastic Beanstalk environment configuration through the Elastic Beanstalk console; click on "Environment details" on the correct environment, "Edit Configuration" in the Overview, and go to "Container" to adjust environment variables (in this case, you will edit the RACK_ENV
field).
While I'm using eb_deployer and not the eb
commandline, during an attempt to deploy a RAILS_ENV: development
I found that db:migrate
etc ran in the development environment, but it still started up the server in production mode. To solve this, passing in both RACK_ENV and RAILS_ENV was necessary in the option_settings:
[{
namespace: 'aws:elasticbeanstalk:application:environment',
option_name: 'RACK_ENV',
value: "development"
},
{
namespace: 'aws:elasticbeanstalk:application:environment',
option_name: 'RAILS_ENV',
value: "development"
}]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With