Below is the step by step guide to deploy rails application on AWS cloud using elastic beanstalk. Deploying any other application stack is also the same. This tutorial requires you to have some pre-requites.
Let’s get started.
$ rails new rails_eb_demo $ cd rails_eb_demo $ rails s
Browse the page http://localhost:3000/. You should see below message on the browser. You should see below landing text message.
“Yay! You’re on Rails!”
Remember, they might change the landing text message but you should get hint that things are good. With that, you can be sure rails is installed properly on your machine.
Navigate to application_controller.rb. Add a dummy method called index
def index end
root 'application#index'
$ aws configure
It will ask your default AWS region, secret key and access key.You can leave the default region as it is but secret key and access key is must. You can get the secret key and access key from IAM user page.
eb init
Follow the on-screen instructions. Basically, it will ask you some details. Like, in which region you want to install the application.
Select ‘Create new application’. And Enter the application name ‘EB_Demo’
Select the language stack as Ruby.
SSH part you can skip it for time being.
After this, your application is created. Nothing concrete is done yet. Under Application, you will create the actual environment. One application can have multiple environments
$ eb create rails_eb_demo
The actual syntax is: $ eb create. eb accepts lot more other options, but for simplicity, we are not going to enter those.
On the background, it does a lot of operations. It uploads the code to S3. It creates an EC2 instance. It prepares the EC2 instance for the rails application. It creates load balancers, an autoscaling group, a security group, and blah blah etc. Bottom line is it makes developer’s life easy. It takes care of dirty jobs.
$ rake secret
Copy the output and provide input for below command.
$ eb setenv SECRET_KEY_BASE= $ rake secret
Select your application. Go to the environment. URL is given on the top right corner. Open the link. You should see the page with “Hello World!” written on it.
But I can help you further to connect the dots. If you have any doubt, leave a comment, I will try to answer at least a few.
Quick Links
Legal Stuff