Before we start exploring the topic described in the title, let’s explain why we consider it a good basis for building web applications - or even a decent backend for mobile projects. We outline five main reasons:
- It allows developers to automate tasks with customized setup routes.
- It’s quick, due to modular design and powerful plugins.
- It supports a lot of Rails libraries for any kind of app.
- It has test suites, allowing the enhancement of coding practices.
- It has a set of conventions for the application’s architecture that may help you in developing the app from scratch.
However, deploying a Ruby on Rails application is not as easy as it seems. The first challenge comes with the selection of the right tool. Although many developers prefer to use Capistrano for deploying Rails applications, it may cause a lot of problems right from the first setup. Fortunately, there is another nice tool for deploying and scaling applications, developed by Amazon for AWS: Elastic Beanstalk. After reading this article, you’ll learn how to deploy Ruby on Rails app on AWS using this tool.
What is Elastic Beanstalk?
As we have mentioned, Elastic Beanstalk is a quick and easy-to-use tool for deploying and scaling an app on AWS. The service performs deployment, allocates resources, provides load balancing and automatic scaling, and monitors the health of the application. Within minutes, the application is ready for use. As a result, AWS Elastic Beanstalk enables your application to handle peak loads or traffic minimizing costs.
Elastic Beanstalk setup
First, make sure that you have an account at AWS. After signing up, you are entitled to receive many free services during the year.
1. We’ve made this tutorial mainly for Mac users, so for installation of the CLI for EB you need to use macOS missing package manager brew
$ brew update
$ brew install awsebcli
$ eb --version
EB CLI 3.2.2 (Python 3.4.3)
2. Let's create a Ruby on Rails app, if you haven’t done it already.
$ *rbenv or rvm optional setup with latest ruby version*
$ gem install rails
$ rails new eb-railsapp
$ cd eb-railsapp
$ git init && git add -A && git commit -m "Initial Commit"
3. You can create some example pages in your Ruby on Rails application with a scaffold.
$ rails g scaffold article title body:text
$ rails db:migrate
$ git add .
$ git commit -am "Add Articles"
4. Make sure that the application works locally. After that, you can start deploying Rails Application to Elastic Beanstalk AWS. Go to your app directory and initialize the Elastic Beanstalk.
$ eb init
5. After running the command above, you’ll see several questions about your app, platform version, configuration etc.
Then, you need to select the correct time zone:
Select a default region
1) us-east-1 : US East (N. Virginia)
2) us-west-1 : US West (N. California)
3) us-west-2 : US West (Oregon)
4) eu-west-1 : EU (Ireland)
5) eu-central-1 : EU (Frankfurt)
6) ap-south-1 : Asia Pacific (Mumbai)
7) ap-southeast-1 : Asia Pacific (Singapore)
8) ap-southeast-2 : Asia Pacific (Sydney)
9) ap-northeast-1 : Asia Pacific (Tokyo)
10) ap-northeast-2 : Asia Pacific (Seoul)
11) sa-east-1 : South America (Sao Paulo)
12) cn-north-1 : China (Beijing)
13) cn-northwest-1 : China (Ningxia)
14) us-east-2 : US East (Ohio)
15) ca-central-1 : Canada (Central)
16) eu-west-2 : EU (London)
17) eu-west-3 : EU (Paris)
(default is 3):
6. After that, the tool asks you to enter the application name. Then, Elastic Beanstalk confirms that you are using Ruby. Next, you need to choose a Ruby version. Finally, it asks you about the access via SSH to check if the remote access is possible and to perform a custom configuration.
Enter Application Name
(default is "eb-railsapp"):
Application eb-railsapp has been created.
It appears you are using Ruby. Is this correct?
(Y/n): y
Select a platform version.
1) Ruby 2.3 (Puma)
2) Ruby 2.2 (Puma)
3) Ruby 2.1 (Puma)
4) Ruby 2.0 (Puma)
5) Ruby 2.3 (Passenger Standalone)
6) Ruby 2.2 (Passenger Standalone)
7) Ruby 2.1 (Passenger Standalone)
8) Ruby 2.0 (Passenger Standalone)
9) Ruby 1.9.3
(default is 1): 1
Do you want to set up SSH for your instances?
Setup the environment
Congrats! You have configured Elastic Beanstalk on your system. Let’s start to create the environment.
1. Basically, this is how Elastic Beanstalk lets you switch between different versions of your Ruby on Rails application.
$ eb create production
After running this command, you deploy rails to AWS. Elastic Beanstalk setup environment, load balancers, security group, EC2 server, auto-scaling group and CloudWatch alarm notifications and more are deployed.
2. The quick status check gets information about your environment and application URL.
Environment details for: production
Application name: eb-railsapp
Region: eu-central-1
Deployed Version: app-ad6f-180419_190755
Environment ID: e-cpd7aashrp
Platform: arn:aws:elasticbeanstalk:eu-central-1::platform/Passenger with Ruby 2.4 running on 64bit Amazon Linux/2.7.2
Tier: WebServer-Standard-1.0
CNAME: production.p3i3g974nv.eu-central-1.elasticbeanstalk.com
Updated: 2018-04-19 16:09:53.185000+00:00
Status: Ready
Health: Green
3. And the last thing that we should do with the Rails app is to generate a SECRET_KEY_BASE environment variable.
$ rake secret
long_secret_key
$ eb setenv SECRET_KEY_BASE=long_secret_key
4. It will update the environment key in secrets.yml. You can update any environment variables using this command.
Now you can run the following command to open the web app:
$ eb open
Now everything is setup and should work.
As you can see, Ruby on Rails works well for developers, enabling the simple and effective development of web applications. We hope this guide will help regular users to perform an AWS Ruby on Rails deployment quickly and easily and choose this development tool to build their websites and applications.
With this post, we start a series of articles written by our development team. This section will be devoted to various aspects of custom web and mobile development.
Rate this post!
540 ratings, average ratings is 4.5 out of 5
Related Posts
Effective Food Delivery App: Key Tips & Best Practices
In this article, we will share our experience in creating a design for a specialized food delivery management software, as well as best practices in designing such an application.
02 August 2023
E-learning Platform Development: Features & Steps to Build
Build an online learning platform with ease: A guide to essential features and step-by-step processes for successful e-learning platform development.
Discovery Phase: a Must-have Step in Software Development
Discovery phase in software development: benefits for your project, details of the main stages, deliverables, and cost for your project.
07 May 2021
How to Integrate 3D Models into Web Apps
We discuss the value of 3D models to your business, pick things to consider before collaborating with your IT partner, and look at 3D web apps.
29 April 2021
Why Use Ruby on Rails and How Can It Benefit Your Next Product?
Learn when to use Ruby on Rails framework for the backend of your app or website and how to choose web developers who use Ruby on Rails programming language.
06 November 2020
Dedicated Team Model: What It Is, Pros & Cons for Your Project
Dedicated team model - a winning approach to scaling your project fast when done right. Find out pros and cons and how to find a dedicated software team that will fit your needs
Let's talk
Is there a challenge your organization or company needs help solving? We’d love to discuss it.
Managing Director, Partner
Andrew Terehin
Thank You!
Your message has been successfully sent.
We will contact you very soon.